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


##########
sql/core/src/test/scala/org/apache/spark/sql/scripting/SqlScriptingInterpreterSuite.scala:
##########
@@ -368,6 +368,238 @@ class SqlScriptingInterpreterSuite extends QueryTest with 
SharedSparkSession {
     }
   }
 
+  test("searched case") {
+    val commands =
+      """
+        |BEGIN
+        | CASE
+        |   WHEN 1 = 1 THEN
+        |     SELECT 42;
+        | END CASE;
+        |END
+        |""".stripMargin
+    val expected = Seq(Seq(Row(42)))
+    verifySqlScriptResult(commands, expected)
+  }
+
+  test("searched case nested") {
+    val commands =
+      """
+        |BEGIN
+        | CASE
+        |   WHEN 1=1 THEN
+        |   CASE
+        |    WHEN 2=1 THEN
+        |     SELECT 41;
+        |   ELSE
+        |     SELECT 42;
+        |   END CASE;
+        | END CASE;
+        |END
+        |""".stripMargin
+    val expected = Seq(Seq(Row(42)))
+    verifySqlScriptResult(commands, expected)
+  }
+
+  test("searched case second case") {
+    val commands =
+      """
+        |BEGIN
+        | CASE
+        |   WHEN 1 = (SELECT 2) THEN
+        |     SELECT 1;
+        |   WHEN 2 = 2 THEN
+        |     SELECT 42;
+        |   WHEN (SELECT * FROM t) THEN

Review Comment:
   @panbingkun to clarify a bit more, scripting works as following (really high 
level):
   - parsing the text and creating a `CompoundBody` logical plan at the root
   - in leaf statements (`SingleStatement`) logical plans of each separate SQL 
statement is saved
   - interpreter iterates through the statements
   - each leaf statement is executed based on the saved logical plan
   
   it's really hard to do what you are asking, since `QueryExecution` (and thus 
analyzer, optimizer, etc) are created and designed to work on the level of a 
single query.
   it would be too much to do what you suggested, but maybe sometime in the 
future if we figure out there's a need and what's the proper way to do so...



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