maropu commented on a change in pull request #29146:
URL: https://github.com/apache/spark/pull/29146#discussion_r464224591
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala
##########
@@ -66,17 +68,29 @@ class SparkSqlAstBuilder(conf: SQLConf) extends
AstBuilder(conf) {
* character in the raw string.
*/
override def visitSetConfiguration(ctx: SetConfigurationContext):
LogicalPlan = withOrigin(ctx) {
- // Construct the command.
- val raw = remainder(ctx.SET.getSymbol)
- val keyValueSeparatorIndex = raw.indexOf('=')
- if (keyValueSeparatorIndex >= 0) {
- val key = raw.substring(0, keyValueSeparatorIndex).trim
- val value = raw.substring(keyValueSeparatorIndex + 1).trim
- SetCommand(Some(key -> Option(value)))
- } else if (raw.nonEmpty) {
- SetCommand(Some(raw.trim -> None))
+ val configKeyValueDef = """([a-zA-Z_\d\\.:]+)\s*=(.*)""".r
+ remainder(ctx.SET.getSymbol).trim match {
+ case configKeyValueDef(key, value) =>
+ SetCommand(Some(key -> Option(value.trim)))
+ case configKeyDef(key) =>
+ SetCommand(Some(key -> None))
+ case s if s == "-v" =>
+ SetCommand(Some("-v" -> None))
+ case s if s.isEmpty =>
+ SetCommand(None)
+ case _ => throw new ParseException("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.", ctx)
+ }
+ }
+
+ override def visitSetQuotedConfiguration(ctx: SetQuotedConfigurationContext)
+ : LogicalPlan = withOrigin(ctx) {
+ val keyStr = ctx.quotedConfigKey().getText
+ if (ctx.value != null) {
+ SetCommand(Some(keyStr -> Option(remainder(ctx.EQ().getSymbol).trim)))
Review comment:
I did so first, but the added tests below failed;
```
val keyStr = ctx.quotedConfigKey().getText
if (ctx.value != null) {
- SetCommand(Some(keyStr -> Option(remainder(ctx.EQ().getSymbol).trim)))
+ SetCommand(Some(keyStr -> Option(ctx.value.getText)))
} else {
SetCommand(Some(keyStr -> None))
}
// The failed tests
assertEqual("SET `spark.sql. key`= -1",
SetCommand(Some("spark.sql. key" -> Some("-1"))))
[info] - Report Error for invalid usage of SET command *** FAILED *** (104
milliseconds)
[info] == FAIL: Plans do not match ===
[info] !SetCommand (spark.sql. key,Some(1)) SetCommand (spark.sql.
key,Some(-1)) (PlanTest.scala:157)
...
```
So, I selected the current one to avoid the test failure. Do you know
something about this behaivour?
----------------------------------------------------------------
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]