anuragmantri commented on code in PR #56792:
URL: https://github.com/apache/spark/pull/56792#discussion_r3533042300
##########
sql/api/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBaseParser.g4:
##########
@@ -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
Review Comment:
Done. I moved the options clause after `tableAlias`.
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/DDLParserSuite.scala:
##########
@@ -2253,6 +2254,50 @@ class DDLParserSuite extends AnalysisTest {
stop = 70))
}
+ test("update table: with options") {
Review Comment:
Done. I added `SPARK-57681:` prefix to all tests added as part of this PR.
##########
sql/core/src/test/scala/org/apache/spark/sql/connector/UpdateTableSuiteBase.scala:
##########
@@ -1232,4 +1235,40 @@ abstract class UpdateTableSuiteBase extends
RowLevelOperationSuiteBase {
Row(1, 100, "hr"),
Row(2, 200, "software")))
}
+
+ // asserts the given SQL options reached every layer that should carry them:
the rewritten
+ // DataSourceV2Relation, the RowLevelOperationInfo passed to the operation
builder, and the
+ // write builder's LogicalWriteInfo
+ protected def checkRowLevelOperationOptions(
+ func: => Unit,
+ expectedOptions: (String, String)*): Unit = {
+ val Seq(qe) = withQueryExecutionsCaptured(spark)(func)
+ val writeRelation = qe.optimizedPlan.collectFirst {
+ case rd: ReplaceData => rd.table
+ case wd: WriteDelta => wd.table
+ }.getOrElse(fail("couldn't find row-level operation in optimized plan"))
+ .asInstanceOf[DataSourceV2Relation]
+ val operation =
writeRelation.table.asInstanceOf[RowLevelOperationTable].operation
+ .asInstanceOf[RowLevelOperationWithOptions]
+ expectedOptions.foreach { case (key, value) =>
+ assert(writeRelation.options.get(key) === value, s"relation option
'$key'")
+ assert(operation.options.get(key) === value, s"row-level operation
option '$key'")
+ assert(table.lastWriteInfo.options().get(key) === value, s"write option
'$key'")
+ }
+ }
+
+ test("update with dynamic options") {
+ createAndInitTable("pk INT NOT NULL, salary INT, dep STRING",
+ """{ "pk": 1, "salary": 100, "dep": "hr" }
+ |{ "pk": 2, "salary": 200, "dep": "software" }
+ |""".stripMargin)
+
+ checkRowLevelOperationOptions(
+ sql(s"UPDATE $tableNameAsString WITH (`write.split-size` = 10) SET
salary = -1 WHERE pk = 1"),
Review Comment:
Thank you, I added tests that exercise the `buildReplaceDataWithUnionPlan`.
I added my analysis of ResolveResolution code and table cache as a PR comment.
Please let me know what you think.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]