cloud-fan commented on code in PR #47442:
URL: https://github.com/apache/spark/pull/47442#discussion_r1701944866
##########
sql/core/src/test/scala/org/apache/spark/sql/scripting/SqlScriptingInterpreterSuite.scala:
##########
@@ -214,4 +215,152 @@ class SqlScriptingInterpreterSuite extends QueryTest with
SharedSparkSession {
)
verifySqlScriptResult(sqlScript, expected)
}
+
+ test ("if") {
+ val commands =
+ """
+ |BEGIN
+ | IF 1=1 THEN
+ | SELECT 42;
+ | END IF;
+ |END
+ |""".stripMargin
+ val expected = Seq(Seq(Row(42)))
+ verifySqlScriptResult(commands, expected)
+ }
+
+ test("if nested") {
+ val commands =
+ """
+ |BEGIN
+ | IF 1=1 THEN
+ | IF 2=1 THEN
+ | SELECT 41;
+ | ELSE
+ | SELECT 42;
+ | END IF;
+ | END IF;
+ |END
+ |""".stripMargin
+ val expected = Seq(Seq(Row(42)))
+ verifySqlScriptResult(commands, expected)
+ }
+
+ test("if else going in if") {
+ val commands =
+ """
+ |BEGIN
+ | IF 1=1
+ | THEN
+ | SELECT 42;
+ | ELSE
+ | SELECT 43;
+ | END IF;
+ |END
+ |""".stripMargin
+
+ val expected = Seq(Seq(Row(42)))
+ verifySqlScriptResult(commands, expected)
+ }
+
+ test("if else if going in else if") {
+ val commands =
+ """
+ |BEGIN
+ | IF 1=2
+ | THEN
+ | SELECT 42;
+ | ELSE IF 1=1
+ | THEN
+ | SELECT 43;
+ | ELSE
+ | SELECT 44;
+ | END IF;
+ |END
+ |""".stripMargin
+
+ val expected = Seq(Seq(Row(43)))
+ verifySqlScriptResult(commands, expected)
+ }
+
+ test("if else going in else") {
+ val commands =
+ """
+ |BEGIN
+ | IF 1=2
+ | THEN
+ | SELECT 42;
+ | ELSE
+ | SELECT 43;
+ | END IF;
+ |END
+ |""".stripMargin
+
+ val expected = Seq(Seq(Row(43)))
+ verifySqlScriptResult(commands, expected)
+ }
+
+ test("if else if going in else") {
+ val commands =
+ """
+ |BEGIN
+ | IF 1=2
+ | THEN
+ | SELECT 42;
+ | ELSE IF 1=3
+ | THEN
+ | SELECT 43;
+ | ELSE
+ | SELECT 44;
+ | END IF;
+ |END
+ |""".stripMargin
+
+ val expected = Seq(Seq(Row(44)))
+ verifySqlScriptResult(commands, expected)
+ }
+
+ test("if with count") {
+ withTable("t") {
+ val commands =
+ """
+ |BEGIN
+ |CREATE TABLE t (a INT, b STRING, c DOUBLE) USING parquet;
Review Comment:
to avoid side effect of tests, let's wrap the test code with `withTable` to
drop the table at the end of test.
--
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]