Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug][spark] fix ambiguous __paimon_file_path when merging from paimo… #5026

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,16 @@ case class MergeIntoPaimonTable(
}
if (hasUpdate(matchedActions)) {
touchedFilePathsSet ++= findTouchedFiles(
targetDS.join(sourceDS, toColumn(mergeCondition), "inner"),
sparkSession)
targetDS.alias("_left").join(sourceDS, toColumn(mergeCondition), "inner"),
sparkSession,
"_left." + FILE_PATH_COLUMN
)
}
if (hasUpdate(notMatchedBySourceActions)) {
touchedFilePathsSet ++= findTouchedFiles(
targetDS.join(sourceDS, toColumn(mergeCondition), "left_anti"),
sparkSession)
targetDS.alias("_left").join(sourceDS, toColumn(mergeCondition), "left_anti"),
sparkSession,
"_left." + FILE_PATH_COLUMN)
}

val targetFilePaths: Array[String] = findTouchedFiles(targetDS, sparkSession)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ trait PaimonCommand extends WithFileStoreTable with ExpressionHelper with SQLCon

protected def findTouchedFiles(
dataset: Dataset[Row],
sparkSession: SparkSession): Array[String] = {
sparkSession: SparkSession,
identifier: String = FILE_PATH_COLUMN): Array[String] = {
import sparkSession.implicits._
dataset
.select(FILE_PATH_COLUMN)
.select(identifier)
.distinct()
.as[String]
.collect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@ abstract class MergeIntoTableTestBase extends PaimonSparkTestBase with PaimonTab
}
}

test(s"Paimon MergeInto: two paimon table") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. I can't understand the effect of this PR by this test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would merge from one paimon table to another, which will have two paimon source join and can cover the ambiguous __paimon_file_path case

withTable("source", "target") {
createTable("target", "a INT, b INT, c STRING", Seq("a"))
createTable("source", "a INT, b INT, c STRING", Seq("a"))

spark.sql("INSERT INTO source values (1, 100, 'c11'), (3, 300, 'c33')")
spark.sql("INSERT INTO target values (1, 10, 'c1'), (2, 20, 'c2')")

spark.sql(s"""
|MERGE INTO target
|USING source
|ON target.a = source.a
|WHEN MATCHED THEN
|UPDATE SET a = source.a, b = source.b, c = source.c
|""".stripMargin)

checkAnswer(
spark.sql("SELECT * FROM target ORDER BY a, b"),
Row(1, 100, "c11") :: Row(2, 20, "c2") :: Nil)
}
}

test(s"Paimon MergeInto: only delete") {
withTable("source", "target") {

Expand Down