cloud-fan commented on code in PR #52016:
URL: https://github.com/apache/spark/pull/52016#discussion_r2416906171
##########
sql/core/src/test/scala/org/apache/spark/sql/connector/UpdateTableSuiteBase.scala:
##########
@@ -735,4 +738,137 @@ abstract class UpdateTableSuiteBase extends
RowLevelOperationSuiteBase {
Row(5)))
}
}
+
+ test("update with UDT column") {
+ withTempView("v2") {
+ val data2 =
+ Seq(
+ (1, Point(21, 31)),
+ (2, Point(22, 32)),
+ (3, Point(23, 33))
+ ).toDF("pk", "pt")
+ data2.createTempView("v2")
+
+ withTable(tableNameAsString) {
+ // Creates a table with a Point column.
+ val data1 = Seq(
+ (1, Point(11, 21)),
+ (2, Point(12, 22)),
+ (3, Point(13, 23))
+ ).toDF("pk", "pt")
+ data1.write.saveAsTable(tableNameAsString)
+
+ checkAnswer(spark.table(tableNameAsString), data1)
+
+ sql(
+ s""" merge into $tableNameAsString as t
+ | using v2
+ | on t.pk = v2.pk
+ | when matched and t.pk <> 2 then update set pt = v2.pt
+ |""".stripMargin)
+ checkAnswer(spark.table(tableNameAsString),
+ Seq(
+ (1, Point(21, 31)),
+ (2, Point(12, 22)),
+ (3, Point(23, 33))
+ ).toDF("pk", "pt"))
+
+ sql(
+ s""" UPDATE $tableNameAsString
+ | SET pt = (select pt from v2 where pk = 2)
+ | WHERE pk = 2
+ |""".stripMargin)
+ checkAnswer(spark.table(tableNameAsString), data2)
+ }
+ }
+ }
+
+ test("unwrap UDT to struct before update") {
+ withTempView("v1", "v2") {
+ val data1 = Seq(
+ (1, Point(11, 21)),
+ (2, Point(12, 22)),
+ (3, Point(13, 23))
+ ).toDF("pk", "pt")
+ data1.createTempView("v1")
+
+ val data2 =
+ Seq(
+ (1, Point(21, 31)),
+ (2, Point(22, 32)),
+ (3, Point(23, 33))
+ ).toDF("pk", "pt")
+ data2.createTempView("v2")
+
+ withTable(tableNameAsString) {
Review Comment:
ditto
##########
sql/core/src/test/scala/org/apache/spark/sql/connector/UpdateTableSuiteBase.scala:
##########
@@ -735,4 +738,137 @@ abstract class UpdateTableSuiteBase extends
RowLevelOperationSuiteBase {
Row(5)))
}
}
+
+ test("update with UDT column") {
+ withTempView("v2") {
+ val data2 =
+ Seq(
+ (1, Point(21, 31)),
+ (2, Point(22, 32)),
+ (3, Point(23, 33))
+ ).toDF("pk", "pt")
+ data2.createTempView("v2")
+
+ withTable(tableNameAsString) {
+ // Creates a table with a Point column.
+ val data1 = Seq(
+ (1, Point(11, 21)),
+ (2, Point(12, 22)),
+ (3, Point(13, 23))
+ ).toDF("pk", "pt")
+ data1.write.saveAsTable(tableNameAsString)
+
+ checkAnswer(spark.table(tableNameAsString), data1)
+
+ sql(
+ s""" merge into $tableNameAsString as t
+ | using v2
+ | on t.pk = v2.pk
+ | when matched and t.pk <> 2 then update set pt = v2.pt
+ |""".stripMargin)
+ checkAnswer(spark.table(tableNameAsString),
+ Seq(
+ (1, Point(21, 31)),
+ (2, Point(12, 22)),
+ (3, Point(23, 33))
+ ).toDF("pk", "pt"))
+
+ sql(
+ s""" UPDATE $tableNameAsString
+ | SET pt = (select pt from v2 where pk = 2)
+ | WHERE pk = 2
+ |""".stripMargin)
+ checkAnswer(spark.table(tableNameAsString), data2)
+ }
+ }
+ }
+
+ test("unwrap UDT to struct before update") {
+ withTempView("v1", "v2") {
+ val data1 = Seq(
+ (1, Point(11, 21)),
+ (2, Point(12, 22)),
+ (3, Point(13, 23))
+ ).toDF("pk", "pt")
+ data1.createTempView("v1")
+
+ val data2 =
+ Seq(
+ (1, Point(21, 31)),
+ (2, Point(22, 32)),
+ (3, Point(23, 33))
+ ).toDF("pk", "pt")
+ data2.createTempView("v2")
+
+ withTable(tableNameAsString) {
+ sql(
+ s"""
+ | create table $tableNameAsString (
Review Comment:
ditto
--
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]