miland-db commented on code in PR #47146: URL: https://github.com/apache/spark/pull/47146#discussion_r1670372148
########## sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/SqlScriptingParserSuite.scala: ########## @@ -161,6 +161,72 @@ class SqlScriptingParserSuite extends SparkFunSuite with SQLHelper { == "SELECT 3") } + test("compound: beginLabel") { + val batch = + """ + |lbl: BEGIN + | SELECT 1; + | SELECT 2; + | INSERT INTO A VALUES (a, b, 3); + | SELECT a, b, c FROM T; + | SELECT * FROM T; + |END""".stripMargin + val tree = parseScript(batch) + assert(tree.collection.length == 5) + assert(tree.collection.forall(_.isInstanceOf[SingleStatement])) + assert(tree.label.equals("lbl")) + } + + test("compound: beginLabel + endLabel") { + val batch = + """ + |lbl: BEGIN + | SELECT 1; + | SELECT 2; + | INSERT INTO A VALUES (a, b, 3); + | SELECT a, b, c FROM T; + | SELECT * FROM T; + |END lbl""".stripMargin + val tree = parseScript(batch) + assert(tree.collection.length == 5) + assert(tree.collection.forall(_.isInstanceOf[SingleStatement])) + assert(tree.label.equals("lbl")) + } + + test("compound: beginLabel + endLabel with different values") { + val batch = + """ + |lbl_begin: BEGIN + | SELECT 1; + | SELECT 2; + | INSERT INTO A VALUES (a, b, 3); + | SELECT a, b, c FROM T; + | SELECT * FROM T; + |END lbl_end""".stripMargin + val e = intercept[SparkException] { + parseScript(batch) + } + assert(e.getErrorClass === "INTERNAL_ERROR") + assert(e.getMessage.contains("Both labels should be same.")) + } + + test("compound: endLabel") { + val batch = + """ + |BEGIN + | SELECT 1; + | SELECT 2; + | INSERT INTO A VALUES (a, b, 3); + | SELECT a, b, c FROM T; + | SELECT * FROM T; + |END lbl""".stripMargin + val e = intercept[SparkException] { + parseScript(batch) + } + assert(e.getErrorClass === "INTERNAL_ERROR") + assert(e.getMessage.contains("End label can't exist without begin label.")) + } + Review Comment: Done -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org