davidm-db commented on code in PR #47648:
URL: https://github.com/apache/spark/pull/47648#discussion_r1711200174


##########
sql/core/src/test/scala/org/apache/spark/sql/scripting/SqlScriptingInterpreterSuite.scala:
##########
@@ -362,4 +367,48 @@ class SqlScriptingInterpreterSuite extends QueryTest with 
SharedSparkSession {
       verifySqlScriptResult(commands, expected)
     }
   }
+
+  test("if's condition must be a boolean statement") {
+    withTable("t") {
+      val commands =
+        """
+          |BEGIN
+          |  IF 1 THEN
+          |    SELECT 45;
+          |  END IF;
+          |END
+          |""".stripMargin
+      checkError(
+        exception = intercept[SqlScriptingException] (
+          runSqlScript(commands)
+        ),
+        errorClass = "INVALID_BOOLEAN_STATEMENT",
+        parameters = Map("invalidStatement" -> "1")
+      )
+    }
+  }
+
+  test("if's condition must return a single row data") {

Review Comment:
   Nice catch! I'm honestly not sure if there is a way to hit our check then, 
but also I'm not sure there isn't... So, I would leave the check just in case, 
but do the tests cases as you did them and that should keep us covered.
   
   @cloud-fan what do you think? Do you know if `ScalarSubquery` is always 
created in boolean expressions? Should we rely on that, or do as I said before 
and keep the check for multiple rows just in case?



##########
sql/core/src/test/scala/org/apache/spark/sql/scripting/SqlScriptingInterpreterSuite.scala:
##########
@@ -362,4 +367,48 @@ class SqlScriptingInterpreterSuite extends QueryTest with 
SharedSparkSession {
       verifySqlScriptResult(commands, expected)
     }
   }
+
+  test("if's condition must be a boolean statement") {
+    withTable("t") {
+      val commands =
+        """
+          |BEGIN
+          |  IF 1 THEN
+          |    SELECT 45;
+          |  END IF;
+          |END
+          |""".stripMargin
+      checkError(
+        exception = intercept[SqlScriptingException] (
+          runSqlScript(commands)
+        ),
+        errorClass = "INVALID_BOOLEAN_STATEMENT",
+        parameters = Map("invalidStatement" -> "1")
+      )
+    }
+  }
+
+  test("if's condition must return a single row data") {

Review Comment:
   Nice catch! I'm honestly not sure if there is a way to hit our check then, 
but also I'm not sure there isn't... So, I would leave the check just in case, 
but do the tests cases as you did them and that should keep us covered.
   
   @cloud-fan what do you think? Do you know if `ScalarSubquery` is always 
created in boolean expressions? Should we rely on that, or do as I said above 
and keep the check for multiple rows just in case?



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