xianyinxin commented on a change in pull request #25115: [SPARK-28351][SQL]
Support DELETE in DataSource V2
URL: https://github.com/apache/spark/pull/25115#discussion_r313242904
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/sources/v2/DataSourceV2SQLSuite.scala
##########
@@ -1862,6 +1862,42 @@ class DataSourceV2SQLSuite extends QueryTest with
SharedSQLContext with BeforeAn
}
}
+ test("DeleteFrom: basic") {
+ val t = "testcat.ns1.ns2.tbl"
+ withTable(t) {
+ sql(s"CREATE TABLE $t (id bigint, data string, p int) USING foo
PARTITIONED BY (id, p)")
+ sql(s"INSERT INTO $t VALUES (2L, 'a', 2), (2L, 'b', 3), (3L, 'c', 3)")
+ sql(s"DELETE FROM $t WHERE id = 2")
+ checkAnswer(spark.table(t), Seq(
+ Row(3, "c", 3)))
+ }
+ }
+
+ test("DeleteFrom: alias") {
+ val t = "testcat.ns1.ns2.tbl"
+ withTable(t) {
+ sql(s"CREATE TABLE $t (id bigint, data string, p int) USING foo
PARTITIONED BY (id, p)")
+ sql(s"INSERT INTO $t VALUES (2L, 'a', 2), (2L, 'b', 3), (3L, 'c', 3)")
+ sql(s"DELETE FROM $t tbl WHERE tbl.id = 2")
+ checkAnswer(spark.table(t), Seq(
+ Row(3, "c", 3)))
+ }
+ }
+
+ test("DeleteFrom: fail if has subquery") {
+ val t = "testcat.ns1.ns2.tbl"
+ withTable(t) {
+ sql(s"CREATE TABLE $t (id bigint, data string, p int) USING foo
PARTITIONED BY (id, p)")
+ sql(s"INSERT INTO $t VALUES (2L, 'a', 2), (2L, 'b', 3), (3L, 'c', 3)")
+ val exc = intercept[AnalysisException] {
+ sql(s"DELETE FROM $t WHERE id IN (SELECT id FROM $t)")
Review comment:
Is that necessary to test correlated subquery? Because correlated subquery
is a subset of subquery and we forbid subquery here, then correlated subquery
is also forbidden.
My thought is later I want to add pre-execution subquery for DELETE, but
correlated subquery is still forbidden, so we can modify the test cases at that
time.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]