-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-57681][SQL] Support dynamic table options for UPDATE #56792
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
base: master
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -740,7 +740,7 @@ dmlStatementNoWith | |
| : insertInto (query | LEFT_PAREN query RIGHT_PAREN queryAlias=tableAlias) #singleInsertQuery | ||
| | fromClause multiInsertQueryBody+ #multiInsertQuery | ||
| | DELETE FROM identifierReference tableAlias whereClause? #deleteFromTable | ||
| | UPDATE identifierReference tableAlias setClause whereClause? #updateTable | ||
| | UPDATE identifierReference optionsClause? tableAlias setClause whereClause? #updateTable | ||
| | MERGE (WITH SCHEMA EVOLUTION)? INTO target=identifierReference targetAlias=tableAlias | ||
|
Member
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. So this PR makes INSERT/DELETE/UPDATE accept WITH(...), but how about MERGE?
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. I intentionally did not add MERGE as the semantics are a bit different since MERGE statements have source and target relations, I'm still thinking about how options would look like there. I can file a separate JIRA and PR for MERGE later. |
||
| USING (source=identifierReference | | ||
| LEFT_PAREN sourceQuery=query RIGHT_PAREN) sourceAlias=tableAlias | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ import org.apache.spark.sql.connector.expressions.{ApplyTransform, BucketTransfo | |
| import org.apache.spark.sql.connector.expressions.LogicalExpressions.bucket | ||
| import org.apache.spark.sql.internal.SQLConf | ||
| import org.apache.spark.sql.types.{DataType, Decimal, IntegerType, LongType, StringType, StructType, TimestampLTZNanosType, TimestampNTZNanosType, TimestampType, TimeType} | ||
| import org.apache.spark.sql.util.CaseInsensitiveStringMap | ||
| import org.apache.spark.storage.StorageLevelMapper | ||
| import org.apache.spark.unsafe.types.{CalendarInterval, UTF8String} | ||
|
|
||
|
|
@@ -2253,6 +2254,50 @@ class DDLParserSuite extends AnalysisTest { | |
| stop = 70)) | ||
| } | ||
|
|
||
| test("update table: with options") { | ||
|
Member
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. Please use test prefix when it's possible. |
||
| parseCompare( | ||
| """ | ||
| |UPDATE testcat.ns1.ns2.tbl WITH (`write.split-size` = 10) | ||
| |SET a='Robert', b=32 | ||
| """.stripMargin, | ||
| UpdateTable( | ||
| UnresolvedRelation(Seq("testcat", "ns1", "ns2", "tbl"), | ||
| new CaseInsensitiveStringMap( | ||
| java.util.Map.of("write.split-size", "10"))), | ||
| Seq(Assignment(UnresolvedAttribute("a"), Literal("Robert")), | ||
| Assignment(UnresolvedAttribute("b"), Literal(32))), | ||
| None)) | ||
| } | ||
|
|
||
| test("update table: with options and alias") { | ||
| parseCompare( | ||
| """ | ||
| |UPDATE testcat.ns1.ns2.tbl WITH (`k` = 'v') AS t | ||
| |SET t.a='Robert', t.b=32 | ||
| |WHERE t.c=2 | ||
| """.stripMargin, | ||
| UpdateTable( | ||
| SubqueryAlias("t", | ||
| UnresolvedRelation(Seq("testcat", "ns1", "ns2", "tbl"), | ||
| new CaseInsensitiveStringMap( | ||
| java.util.Map.of("k", "v")))), | ||
| Seq(Assignment(UnresolvedAttribute("t.a"), Literal("Robert")), | ||
| Assignment(UnresolvedAttribute("t.b"), Literal(32))), | ||
| Some(EqualTo(UnresolvedAttribute("t.c"), Literal(2))))) | ||
| } | ||
|
|
||
| test("update table: options without values are not allowed") { | ||
| val sql = "UPDATE testcat.ns1.ns2.tbl WITH (`split-size`) SET a = 1" | ||
| checkError( | ||
| exception = parseException(sql), | ||
| condition = "_LEGACY_ERROR_TEMP_0035", | ||
| parameters = Map("message" -> "Values must be specified for key(s): [split-size]"), | ||
| context = ExpectedContext( | ||
| fragment = "testcat.ns1.ns2.tbl", | ||
| start = 7, | ||
| stop = 25)) | ||
| } | ||
|
|
||
| test("merge into table: basic") { | ||
| parseCompare( | ||
| """ | ||
|
|
||
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.
Although this seems to follow read path, this is inconsistent with our existing
INSERTsyntax.spark/sql/api/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBaseParser.g4
Lines 592 to 595 in 972f696
UPDATEshould followINSERTstyle.