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

[Spark] Execute MERGE using Dataframe API in Scala #3456

Merged
merged 4 commits into from
Aug 1, 2024

Conversation

johanl-db
Copy link
Collaborator

Description

Due to Spark unfortunate behavior of resolving plan nodes it doesn't know, the DeltaMergeInto plan created when using the MERGE scala API needs to be manually resolved to ensure spark doesn't interfere with its analysis.

This currently completely bypasses Spark's analysis as we then manually execute the MERGE command which has negatiev effects, e.g. the execution is not visible in QueryExecutionListener.

This change addresses this issue, by executing the plan using the Dataframe API after it's manually resolved so that the command goes through the regular code path.

Resolves #1521

How was this patch tested?

Covered by existing tests.

@longvu-db
Copy link
Contributor

It is necessary to add some tests that check that Merge is actually captured by the QueryExecutionListener using PlanCapturingListener() in DeltaTestUtilsBase?

Copy link
Collaborator Author

@johanl-db johanl-db left a comment

Choose a reason for hiding this comment

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

I added a test

withKeyValueData(
source = (0, 0) :: (1, 10) :: Nil,
target = (1, 1) :: (2, 2) :: Nil) { case (sourceName, targetName) =>
val plans = withLogicalPlansCaptured(spark, optimizedPlan = false) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it necessary to test for the case optimizedPlan = true also?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, that doesn't bring much, the optimizer has no impact on MergeIntoCommand

Copy link
Contributor

@longvu-db longvu-db left a comment

Choose a reason for hiding this comment

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

Great work!

@tdas
Copy link
Contributor

tdas commented Aug 1, 2024

the build for spark-master failed for unrelated reason. so merging this.

@tdas tdas merged commit 9ca8e82 into delta-io:master Aug 1, 2024
9 of 10 checks passed
vkorukanti pushed a commit to vkorukanti/delta that referenced this pull request Aug 20, 2024
(cherrypick of delta-io#3456)

Due to Spark unfortunate behavior of resolving plan nodes it doesn't
know, the `DeltaMergeInto` plan created when using the MERGE scala API
needs to be manually resolved to ensure spark doesn't interfere with its
analysis.

This currently completely bypasses Spark's analysis as we then manually
execute the MERGE command which has negatiev effects, e.g. the execution
is not visible in QueryExecutionListener.

This change addresses this issue, by executing the plan using the
Dataframe API after it's manually resolved so that the command goes
through the regular code path.

Resolves delta-io#1521
Covered by existing tests.
vkorukanti added a commit that referenced this pull request Aug 20, 2024
(cherrypick of #3456)

Due to Spark unfortunate behavior of resolving plan nodes it doesn't
know, the `DeltaMergeInto` plan created when using the MERGE scala API
needs to be manually resolved to ensure spark doesn't interfere with its
analysis.

This currently completely bypasses Spark's analysis as we then manually
execute the MERGE command which has negatiev effects, e.g. the execution
is not visible in QueryExecutionListener.

This change addresses this issue, by executing the plan using the
Dataframe API after it's manually resolved so that the command goes
through the regular code path.

Resolves #1521 Covered by
existing tests.

Co-authored-by: Johan Lasperas <johan.lasperas@databricks.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] MergeIntoCommand not visible in QueryExecutionListener when using Python/Scala API
3 participants