maropu commented on a change in pull request #29146:
URL: https://github.com/apache/spark/pull/29146#discussion_r462884139



##########
File path: 
sql/core/src/test/scala/org/apache/spark/sql/execution/SparkSqlParserSuite.scala
##########
@@ -61,6 +63,64 @@ class SparkSqlParserSuite extends AnalysisTest {
   private def intercept(sqlCommand: String, messages: String*): Unit =
     interceptParseException(parser.parsePlan)(sqlCommand, messages: _*)
 
+  test("Checks if SET/RESET can accept all the configurations") {
+    // Force to build static SQL configurations
+    StaticSQLConf
+    SQLConf.sqlConfEntries.values.asScala.foreach { e =>
+      assertEqual(s"SET ${e.key}", SetCommand(Some(e.key -> None)))
+      if (e.defaultValue.isDefined) {
+        assertEqual(s"SET ${e.key}=${e.defaultValueString}",
+          SetCommand(Some(e.key -> Some(e.defaultValueString))))
+      }
+      assertEqual(s"RESET ${e.key}", ResetCommand(Some(e.key)))
+    }
+  }
+
+  test("Report Error for invalid usage of SET command") {
+    assertEqual("SET", SetCommand(None))
+    assertEqual("SET -v", SetCommand(Some("-v", None)))
+    assertEqual("SET spark.sql.key", SetCommand(Some("spark.sql.key" -> None)))
+    assertEqual("SET spark:sql:key=false", SetCommand(Some("spark:sql:key" -> 
Some("false"))))
+    assertEqual("SET spark:sql:key=", SetCommand(Some("spark:sql:key" -> 
Some(""))))
+    assertEqual("SET spark:sql:key=  ", SetCommand(Some("spark:sql:key" -> 
Some(""))))
+    assertEqual("SET spark:sql:key=-1 ", SetCommand(Some("spark:sql:key" -> 
Some("-1"))))
+    assertEqual("SET spark:sql:key = -1", SetCommand(Some("spark:sql:key" -> 
Some("-1"))))
+    assertEqual("SET `spark.sql.    key`=value",
+      SetCommand(Some("spark.sql.    key" -> Some("value"))))
+
+    val expectedErrMsg = "Expected format is 'SET', 'SET key', or " +
+      "'SET key=value'. If you want to include special characters in key, " +
+      "please use quotes, e.g., SET `ke y`=value."
+    intercept("SET spark.sql.key value", expectedErrMsg)
+    intercept("SET spark.sql.key   'value'", expectedErrMsg)
+    intercept("SET    spark.sql.key \"value\" ", expectedErrMsg)
+    intercept("SET spark.sql.key value1 value2", expectedErrMsg)
+
+    // TODO: Needs to make the error message more meaningful for users
+    intercept("SET spark.sql.   key=value", "failed predicate")
+    intercept("SET spark.sql   :key=value", "failed predicate")
+    intercept("SET spark.sql .  key=value", "failed predicate")
+  }
+
+  test("Report Error for invalid usage of RESET command") {
+    assertEqual("RESET", ResetCommand(None))
+    assertEqual("RESET spark.sql.key", ResetCommand(Some("spark.sql.key")))
+    assertEqual("RESET spark.sql.key ", ResetCommand(Some("spark.sql.key")))
+    assertEqual("RESET `spark.sql.    key`", ResetCommand(Some("spark.sql.    
key")))
+
+    val expectedErrMsg = "Expected format is 'RESET' or 'RESET key'. " +
+      "If you want to include special characters in key, " +
+      "please use quotes, e.g., RESET `ke y`."
+    intercept("RESET spark.sql.key1 key2", expectedErrMsg)
+    intercept("RESET spark.  sql.key1 key2", expectedErrMsg)
+    intercept("RESET spark.sql.key1 key2 key3", expectedErrMsg)
+
+    // TODO: Needs to make the error message more meaningful for users
+    intercept("RESET spark.sql:    key", "failed predicate")

Review comment:
       Added.




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

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