Uh oh!
There was an error while loading. Please reload this page.
[SPARK-31102][SQL] Spark-sql fails to parse when contains comment. - #27920
[SPARK-31102][SQL] Spark-sql fails to parse when contains comment.#27920javierivanov wants to merge 5 commits into
Conversation
maropu
commented
Mar 16, 2020
ok to test |
SparkQA
commented
Mar 16, 2020
Test build #119825 has finished for PR 27920 at commit
|
| """SELECT concat('test', 'comment') -- someone's comment here \\ | ||
| | comment continues here with single ' quote \\ | ||
| | extra ' \\ | ||
| | ;""".stripMargin -> "testcomment" |
There was a problem hiding this comment.
Why you did you remove the existing tests instead of adding new tests?
There was a problem hiding this comment.
Hey @maropu !
The SQL parser does not recognize line-continuity per se.
scala> sql(s"""SELECT concat('test', 'comment') -- someone's comment here \\\ncomment continues here with single ' quote \\\nextra ' \\""")
org.apache.spark.sql.catalyst.parser.ParseException:
mismatched input 'continues' expecting {<EOF>, ',', 'CLUSTER', 'DISTRIBUTE', 'EXCEPT', 'FROM', 'GROUP', 'HAVING', 'INTERSECT', 'LATERAL', 'LIMIT', 'ORDER', 'MINUS', 'SORT', 'UNION', 'WHERE', 'WINDOW', '-'}(line 2, pos 8)
== SQL ==
SELECT concat('test', 'comment') -- someone's comment here \
comment continues here with single ' quote \
--------^^^
extra ' \
It works just fine for inline comments included backslash:
scala> sql(s"""SELECT concat('test', 'comment') -- someone's comment here \\\n,2""") show
+---------------------+---+
|concat(test, comment)| 2|
+---------------------+---+
| testcomment| 2|
+---------------------+---+
But does not work outside the inline comment(the backslash):
sql(s"""SELECT concat('test', 'comment') -- someone's comment here \n,2\\\n""")
org.apache.spark.sql.catalyst.parser.ParseException:
extraneous input '\' expecting <EOF>(line 2, pos 2)
== SQL ==
SELECT concat('test', 'comment') -- someone's comment here
,2\
--^^^
Previously worked fine because of this very bug, the insideComment flag ignored everything until the end of the string. But the spark SQL parser does not recognize the backslashes. Line-continuity can be added to the CLI. But I think that feature should be added directly to the SQL parser to avoid confusion.
Let me know your thoughts 👍
There was a problem hiding this comment.
If we can, the fix in SqlBase.g4 (SIMPLE_COMENT) looks fine to me and I think the queries above should work in Spark SQL: https://github.com/apache/spark/blob/master/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4#L1811 Could you try?
There was a problem hiding this comment.
@maropu I have added the fix. Let me know what you think :)
maropu
commented
Mar 16, 2020
cc: @wangyum |
maropu
commented
Apr 9, 2020
@javierivanov Any update? |
javierivanov
commented
Apr 9, 2020
@maropu I am extremly sorry, I will commit soon :) |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
SparkQA
commented
Apr 13, 2020
Test build #121162 has finished for PR 27920 at commit
|
maropu
commented
Apr 13, 2020
retest this please |
SparkQA
commented
Apr 13, 2020
Test build #121181 has finished for PR 27920 at commit
|
SparkQA
commented
Apr 13, 2020
Test build #121211 has finished for PR 27920 at commit
|
maropu
commented
Apr 14, 2020
retest this please |
maropu
commented
Apr 14, 2020
Could you check this? @wangyum |
SparkQA
commented
Apr 14, 2020
Test build #121243 has finished for PR 27920 at commit
|
maropu
commented
Apr 14, 2020
retest this please |
SparkQA
commented
Apr 14, 2020
Test build #121260 has finished for PR 27920 at commit
|
javierivanov
commented
May 6, 2020
| SIMPLE_COMMENT | ||
| : '--' ~[\r\n]* '\r'? '\n'? -> channel(HIDDEN) | ||
| : '--' ('\\\n' | ~[\r\n])* '\r'? '\n'? -> channel(HIDDEN) |
There was a problem hiding this comment.
Ur, one more comment; could you add tests in sql-tests/inputs/comments.sql, too?
maropu
commented
May 6, 2020
retest this please |
maropu
commented
May 6, 2020
cc: @cloud-fan |
| test("SPARK-30049 Should not complain for quotes in commented with multi-lines") { | ||
| runCliWithin(1.minute)( | ||
| """SELECT concat('test', 'comment') -- someone's comment here \\ |
There was a problem hiding this comment.
so double-slash doesn't work any more?
There was a problem hiding this comment.
It was a previous mistake since using Scala multi-line strings it auto escape chars.
| test("single comment case two") { | ||
| val plan = table("a").select(star()) | ||
| assertEqual("-- single comment\\\nwith line continuity\nSELECT * FROM a", plan) |
There was a problem hiding this comment.
how to interpret \\\n? An escaped slash and a new-line symbol?
There was a problem hiding this comment.
Thats correct. Inline strings need to be escaped.
SparkQA
commented
May 7, 2020
Test build #122383 has finished for PR 27920 at commit
|
thanks, merging to master! |
cloud-fan
commented
May 12, 2020
it conflicts with 3.0, @javierivanov can you open a new PR for 3.0? Thanks! |
maropu
commented
May 17, 2020
@javierivanov kindly ping: #27920 (comment) |
This PR introduces a change to false for the insideComment flag on a newline. Fixing the issue introduced by SPARK-30049.
Previously on SPARK-30049 a comment containing an unclosed quote produced the following issue:
```
spark-sql> SELECT 1 -- someone's comment here
> ;
Error in query:
extraneous input ';' expecting <EOF>(line 2, pos 0)
== SQL ==
SELECT 1 -- someone's comment here
;
^^^
```
This was caused because there was no flag for comment sections inside the splitSemiColon method to ignore quotes. SPARK-30049 added that flag and fixed the issue, but introduced the follwoing problem:
```
spark-sql> select
> 1,
> -- two
> 2;
Error in query:
mismatched input '<EOF>' expecting {'(', 'ADD', 'AFTER', 'ALL', 'ALTER', ...}(line 3, pos 2)
== SQL ==
select
1,
--^^^
```
This issue is generated by a missing turn-off for the insideComment flag with a newline.
No
- For previous tests using line-continuity(`\`) it was added a line-continuity rule in the SqlBase.g4 file to add the functionality to the SQL context.
- A new test for inline comments was added.
Closesapache#27920 from javierivanov/SPARK-31102.
Authored-by: Javier Fuentes <j.fuentes.m@icloud.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>This PR introduces a change to false for the insideComment flag on a newline. Fixing the issue introduced by SPARK-30049. Backport to 3.0 from #27920 Previously on SPARK-30049 a comment containing an unclosed quote produced the following issue: ``` spark-sql> SELECT 1 -- someone's comment here > ; Error in query: extraneous input ';' expecting <EOF>(line 2, pos 0) == SQL == SELECT 1 -- someone's comment here ; ^^^ ``` This was caused because there was no flag for comment sections inside the splitSemiColon method to ignore quotes. SPARK-30049 added that flag and fixed the issue, but introduced the follwoing problem: ``` spark-sql> select > 1, > -- two > 2; Error in query: mismatched input '<EOF>' expecting {'(', 'ADD', 'AFTER', 'ALL', 'ALTER', ...}(line 3, pos 2) == SQL == select 1, --^^^ ``` This issue is generated by a missing turn-off for the insideComment flag with a newline. No - For previous tests using line-continuity(`\`) it was added a line-continuity rule in the SqlBase.g4 file to add the functionality to the SQL context. - A new test for inline comments was added. Closes#27920 from javierivanov/SPARK-31102. Authored-by: Javier Fuentes <j.fuentes.micloud.com> Signed-off-by: Wenchen Fan <wenchendatabricks.com> ### What changes were proposed in this pull request? ### Why are the changes needed? ### Does this PR introduce _any_ user-facing change? ### How was this patch tested? Closes#28565 from javierivanov/SPARK-3.0-31102. Authored-by: Javier Fuentes <j.fuentes.m@icloud.com> Signed-off-by: Takeshi Yamamuro <yamamuro@apache.org>
What changes were proposed in this pull request?
This PR introduces a change to false for the insideComment flag on a newline. Fixing the issue introduced by SPARK-30049.
Why are the changes needed?
Previously on SPARK-30049 a comment containing an unclosed quote produced the following issue:
This was caused because there was no flag for comment sections inside the splitSemiColon method to ignore quotes. SPARK-30049 added that flag and fixed the issue, but introduced the follwoing problem:
This issue is generated by a missing turn-off for the insideComment flag with a newline.
Does this PR introduce any user-facing change?
No
How was this patch tested?
\) it was added a line-continuity rule in the SqlBase.g4 file to add the functionality to the SQL context.