samsetegne commented on a change in pull request #27567: [SPARK-30822][SQL]
Remove semicolon at the end of a sql query
URL: https://github.com/apache/spark/pull/27567#discussion_r384760208
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala
##########
@@ -45,7 +45,10 @@ class SparkSqlParser(conf: SQLConf) extends
AbstractSqlParser(conf) {
private val substitutor = new VariableSubstitution(conf)
protected override def parse[T](command: String)(toResult: SqlBaseParser =>
T): T = {
- super.parse(substitutor.substitute(command))(toResult)
+ val trimmed_command = if (command.trim.endsWith(";")) {
Review comment:
@maropu I updated the PR as described including some tests, let me know what
you think. To expand on the example in my earlier reply:
```scala
// Below query is understood to be a single statement
sql("select 1, 2, 3;; ;; ; ")
res1: org.apache.spark.sql.DataFrame = [1: int, 2: int ... 1 more field]
// Below multi-statement query appropriately fails
sql("select 1, 2, 3;; ;; select 4, 5, 6; ")
org.apache.spark.sql.catalyst.parser.ParseException:
extraneous input 'select' expecting {<EOF>, ';'}(line 1, pos 20)
// == SQL ==
// select 1, 2, 3;; ;; select 4, 5, 6
// --------------------^^^
```
----------------------------------------------------------------
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]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]