-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-31102][SQL] Spark-sql fails to parse when contains comment. #27920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1814,7 +1814,7 @@ fragment LETTER | |
; | ||
|
||
SIMPLE_COMMENT | ||
: '--' ~[\r\n]* '\r'? '\n'? -> channel(HIDDEN) | ||
: '--' ('\\\n' | ~[\r\n])* '\r'? '\n'? -> channel(HIDDEN) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ur, one more comment; could you add tests in |
||
; | ||
|
||
BRACKETED_COMMENT | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,11 +55,16 @@ class PlanParserSuite extends AnalysisTest { | |
With(plan, ctes) | ||
} | ||
|
||
test("single comment") { | ||
test("single comment case one") { | ||
val plan = table("a").select(star()) | ||
assertEqual("-- single comment\nSELECT * FROM a", plan) | ||
} | ||
|
||
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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how to interpret There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thats correct. Inline strings need to be escaped. |
||
} | ||
|
||
test("bracketed comment case one") { | ||
val plan = table("a").select(star()) | ||
assertEqual( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -460,18 +460,20 @@ class CliSuite extends SparkFunSuite with BeforeAndAfterAll with BeforeAndAfterE | |
) | ||
} | ||
|
||
test("SPARK-30049 Should not complain for quotes in commented with multi-lines") { | ||
test("SPARK-31102 spark-sql fails to parse when contains comment") { | ||
runCliWithin(1.minute)( | ||
"""SELECT concat('test', 'comment') -- someone's comment here \\ | ||
| comment continues here with single ' quote \\ | ||
| extra ' \\ | ||
|;""".stripMargin -> "testcomment" | ||
"""SELECT concat('test', 'comment'), | ||
| -- someone's comment here | ||
| 2;""".stripMargin -> "testcomment" | ||
) | ||
} | ||
|
||
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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so double-slash doesn't work any more? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was a previous mistake since using Scala multi-line strings it auto escape chars. |
||
| comment continues here with single ' quote \\ | ||
| extra ' \\ | ||
| ;""".stripMargin -> "testcomment" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why you did you remove the existing tests instead of adding new tests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @maropu !
It works just fine for inline comments included backslash:
But does not work outside the inline comment(the backslash):
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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we can, the fix in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @maropu I have added the fix. Let me know what you think :) |
||
"""SELECT concat('test', 'comment') -- someone's comment here \ | ||
| comment continues here with single ' quote \ | ||
| extra ' \ | ||
|;""".stripMargin -> "testcomment" | ||
) | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.