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-51513][SQL] Fix RewriteMergeIntoTable rule produces unresolved plan #50281

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

wangyum
Copy link
Member

@wangyum wangyum commented Mar 14, 2025

What changes were proposed in this pull request?

This patch addresses the issue where the RewriteMergeIntoTable rule produces an unresolved plan. The changes ensure that the MERGE INTO operation correctly handles cases where the source table contains rows that need to be inserted into the target table.

Why are the changes needed?

Fix query failure.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Unit test.

Was this patch authored or co-authored using generative AI tooling?

No.

@github-actions github-actions bot added the SQL label Mar 14, 2025
@wangyum
Copy link
Member Author

wangyum commented Mar 15, 2025

cc @cloud-fan

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

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

Thank you for the fix, @wangyum .

@@ -1091,6 +1092,8 @@ object FoldablePropagation extends Rule[LogicalPlan] {
object SimplifyCasts extends Rule[LogicalPlan] {
def apply(plan: LogicalPlan): LogicalPlan = plan.transformAllExpressionsWithPruning(
_.containsPattern(CAST), ruleId) {
case c @ Cast(e: Attribute, StringType, _, _)
Copy link
Contributor

Choose a reason for hiding this comment

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

does it have to be Attribute? I think we should match NamedExpression so that nested fields can also be covered.

@cloud-fan
Copy link
Contributor

@aokolnychyi can you also take a look?

@the-sakthi
Copy link
Member

LGTM

@@ -449,7 +449,8 @@ class Analyzer(override val catalogManager: CatalogManager) extends RuleExecutor
Batch("DML rewrite", fixedPoint,
RewriteDeleteFromTable,
RewriteUpdateTable,
RewriteMergeIntoTable),
RewriteMergeIntoTable,
ResolveOutputRelation),
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add some comments to explain how these rules above can make the plan unresolved and we need to run ResolveOutputRelation to re-resolve it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants