zeal-thinker commented on code in PR #48554:
URL: https://github.com/apache/spark/pull/48554#discussion_r1811064535


##########
sql/core/src/test/scala/org/apache/spark/sql/sources/InsertSuite.scala:
##########
@@ -2731,6 +2731,27 @@ class InsertSuite extends DataSourceTest with 
SharedSparkSession {
       }
     }
   }
+
+  test("spark 50005: Can't overwrite a table that is also being read from") {
+    val tableName1 = "t1"
+    val tableName2 = "t2"
+    withTable(tableName1, tableName2) {
+      sql(s"CREATE TABLE $tableName1 (a STRING, b INT) USING parquet")
+      sql(s"CREATE TABLE $tableName2 (a STRING, b INT) USING parquet")
+      checkError(
+        exception = intercept[AnalysisException] {
+          sql(
+            s"""
+              |INSERT OVERWRITE TABLE $tableName1
+              |SELECT * FROM $tableName2 tb
+              |WHERE NOT EXISTS(SELECT ta.b FROM $tableName1 ta WHERE tb.b = 
ta.b)

Review Comment:
   Do you want to add one more unit test with more nested query to make sure 
that logic works fine?
   
   Something like:
   INSERT OVERWRITE TABLE $tableName1 
     SELECT * FROM $tableName2 tb WHERE NOT EXISTS
       (SELECT * FROM $tableName3 tc WHERE tc.a IN 
         (SELECT td.a FROM $tableName4 td WHERE td.a IN 
           (SELECT ta.a FROM $tableName1 ta)))



-- 
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]

Reply via email to