-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-32030][SPARK-32127][SQL] Support unlimited MATCHED and NOT MATCHED clauses in MERGE INTO #28875
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
Conversation
|
@cloud-fan @brkyvz , pls take a look. |
|
Test build #124306 has finished for PR 28875 at commit
|
sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4
Outdated
Show resolved
Hide resolved
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
Outdated
Show resolved
Hide resolved
| } | ||
| if (matchedActions.groupBy(_.getClass).mapValues(_.size).exists(_._2 > 1)) { | ||
| val matchedActionSize = matchedActions.length | ||
| if (matchedActionSize >= 2 && !matchedActions.init.forall(_.condition.nonEmpty)) { |
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.
we can still write .children.isEmpty, then we don't need to change v2Commands.scala
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.
I don't think so, because the children of InsertAction and UpdateAction actually include condition and assignments. There may be cases where there're assignments and condition being ignored but children is nonEmpty.
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.
then this is an existing bug?
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.
Yes, it was a bug.
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.
can you send a new PR against branch 3.0 to fix this bug?
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.
Submitted a pr at #28943.
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/DDLParserSuite.scala
Outdated
Show resolved
Hide resolved
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala
Outdated
Show resolved
Hide resolved
|
Test build #124396 has finished for PR 28875 at commit
|
|
Test build #124379 has finished for PR 28875 at commit
|
|
Test build #124381 has finished for PR 28875 at commit
|
| } | ||
|
|
||
| test("merge into table: the first matched clause must have a condition if there's a second") { | ||
| test("merge into table: only the last matched clause can omit the condition") { |
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.
shall we test the same thing for not matched clause?
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.
done.
|
|
||
| sealed abstract class MergeAction( | ||
| condition: Option[Expression]) extends Expression with Unevaluable { | ||
| val condition: Option[Expression]) extends Expression with Unevaluable { |
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.
to simplify the code a little bit:
sealed trait MergeAction extends Expression with Unevaluable {
def condition: Option[Expression]
...
}
Then we can just write
case class DeleteAction(condition: Option[Expression]) extends MergeAction
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.
done.
|
Test build #124585 has finished for PR 28875 at commit
|
|
retest it please. |
|
retest it please |
|
ok to test |
|
Test build #5046 has finished for PR 28875 at commit
|
|
Test build #5047 has finished for PR 28875 at commit
|
|
Test build #124625 has finished for PR 28875 at commit
|
|
thanks, merging to master! |
|
Thanks @cloud-fan ! |
What changes were proposed in this pull request?
This PR add unlimited MATCHED and NOT MATCHED clauses in MERGE INTO statement.
Why are the changes needed?
Now the MERGE INTO syntax is,
It would be nice if we support unlimited MATCHED and NOT MATCHED clauses in MERGE INTO statement, because users may want to deal with different "AND "s, the result of which just like a series of "CASE WHEN"s. The expected syntax looks like
where when_matched_clause is
and when_not_matched_clause is
matched_action can be one of
and not_matched_action can be one of
Does this PR introduce any user-facing change?
Yes. The SQL command changes, but it is backward compatible.
How was this patch tested?
New tests added.