-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-54496][SQL] Fix Merge Into Schema Evolution for Dataframe API #53207
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -916,19 +916,29 @@ case class MergeIntoTable( | |
| false | ||
| } else { | ||
| val actions = matchedActions ++ notMatchedActions | ||
| val assignments = actions.collect { | ||
| case a: UpdateAction => a.assignments | ||
| case a: InsertAction => a.assignments | ||
| }.flatten | ||
| val sourcePaths = DataTypeUtils.extractAllFieldPaths(sourceTable.schema) | ||
| assignments.forall { assignment => | ||
| assignment.resolved || | ||
| (assignment.value.resolved && sourcePaths.exists { | ||
| path => MergeIntoTable.isEqual(assignment, path) | ||
| }) | ||
| val hasStarActions = actions.exists { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The call to canEvaluateSchemaEvolution (that guards whether the schema evolution check gets evaluated) gets called with updateStar and insertStar. This is triggered in the Dataframe API, and revealed I had missed this case. So here I return false to explicitly skip until they are resolved. Else this hits an analysis error later. This was not triggered in SQL case where the stars got resolved earlier. |
||
| case _: UpdateStarAction => true | ||
| case _: InsertStarAction => true | ||
| case _ => false | ||
| } | ||
| if (hasStarActions) { | ||
| // need to resolve star actions first | ||
| false | ||
| } else { | ||
| val assignments = actions.collect { | ||
| case a: UpdateAction => a.assignments | ||
| case a: InsertAction => a.assignments | ||
| }.flatten | ||
| val sourcePaths = DataTypeUtils.extractAllFieldPaths(sourceTable.schema) | ||
| assignments.forall { assignment => | ||
| assignment.resolved || | ||
| (assignment.value.resolved && sourcePaths.exists { | ||
| path => MergeIntoTable.isEqual(assignment, path) | ||
| }) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private lazy val sourceSchemaForEvolution: StructType = | ||
| MergeIntoTable.sourceSchemaForSchemaEvolution(this) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a bug here, as it actually hits both the sourceTable and targetTable and tries schema evolution on both, when actually schema evolution should always be performed only for target table.
I had done it this way because of the limitation of transformUpWithNewOutput that it doesn't re-map the attribues of the top level object (MergeIntoTable). See #52866 (comment) for my finding. So I transformed all children of MergeIntoTable and assumed that the match with SupportsRowLevelOperation Table would be enough to only do schema evolution on the targetTable, but I was wrong.
So the fix is to explicitly transform on the MergeIntoTable's targetTable, and I add an extra rewriteAttrs to rewrite the top level MergeIntoTable object.