davidm-db commented on code in PR #47462:
URL: https://github.com/apache/spark/pull/47462#discussion_r1689273146
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/SqlScriptingParserSuite.scala:
##########
@@ -263,6 +264,37 @@ class SqlScriptingParserSuite extends SparkFunSuite with
SQLHelper {
assert(tree.label.nonEmpty)
}
+ test("declare at the beginning") {
+ val sqlScriptText =
+ """
+ |BEGIN
+ | DECLARE testVariable1 VARCHAR(50);
+ | DECLARE testVariable2 INTEGER;
+ |END""".stripMargin
+ val tree = parseScript(sqlScriptText)
+ assert(tree.collection.length == 2)
+ assert(tree.collection.forall(_.isInstanceOf[SingleStatement]))
+ assert(tree.collection.forall(
+ _.asInstanceOf[SingleStatement].parsedPlan.isInstanceOf[CreateVariable]))
+ }
+
+ test("declare after beginning") {
+ val sqlScriptText =
+ """
+ |BEGIN
+ | SELECT 1;
+ | DECLARE testVariable INTEGER;
+ |END""".stripMargin
+ checkError(
+ exception = intercept[SparkException] {
+ parseScript(sqlScriptText)
+ },
+ errorClass = "INVALID_VARIABLE_DECLARATION.ONLY_AT_BEGINNING",
+ parameters = Map("varName" -> "testVariable", "lineNumber" -> "4"))
+ }
+
+ // TODO Add test for INVALID_VARIABLE_DECLARATION.NOT_ALLOWED_IN_SCOPE
exception
Review Comment:
let's not forget to add this test as well, now that the PR for variable
checks has been merged.
--
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]