-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-28880][SQL] Support ANSI nested bracketed comments #27495
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 2 commits
464cd03
c782bac
0a21b5e
1b9d1da
3d03688
596d905
7760f91
efe98fa
a2241ae
519f47f
f2e7fb5
1b188d7
e1d3b3b
812b16d
f5a817f
99d9187
8e89a87
8118ab5
116e9b8
25d0863
f1806ef
a32cb54
93eb3c5
20452bc
0a42a59
660cd34
9c856b7
48814c3
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 |
|---|---|---|
|
|
@@ -1794,7 +1794,7 @@ BRACKETED_EMPTY_COMMENT | |
| ; | ||
|
|
||
| BRACKETED_COMMENT | ||
| : '/*' ~[+] .*? '*/' -> channel(HIDDEN) | ||
| : '/*' ~[+] ( ~'/' | ~'*' '/' ~'*' )*? BRACKETED_COMMENT? ( ~'/' | ~'*' '/' ~'*' )*? '*/' -> channel(HIDDEN) | ||
|
Member
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.
Contributor
Author
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. I'm sorry. Maybe I lost some information. |
||
| ; | ||
|
|
||
| WS | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,54 @@ class PlanParserSuite extends AnalysisTest { | |
| With(plan, ctes) | ||
| } | ||
|
|
||
| test("single comment") { | ||
| val plan = table("a").select(star()) | ||
| assertEqual("-- single comment\nSELECT * FROM a", plan) | ||
| } | ||
|
|
||
| test("bracketed comment case one") { | ||
| val plan = table("a").select(star()) | ||
| assertEqual("/* This is an example of SQL which should not execute:\n" + | ||
|
Member
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. Could you follow a format like this?
Contributor
Author
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. OK. Thanks. |
||
| " * select 'multi-line';\n" + | ||
| " */\n" + | ||
| "SELECT * FROM a", plan) | ||
| } | ||
|
|
||
| test("bracketed comment case two") { | ||
| val plan = table("a").select(star()) | ||
| assertEqual("/*\n" + | ||
| "SELECT 'trailing' as x1; -- inside block comment\n" + | ||
| "*/\n" + | ||
| "SELECT * FROM a", plan) | ||
| } | ||
|
|
||
| test("nexted bracketed comment case one") { | ||
|
Member
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. nit:
Contributor
Author
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. OK |
||
| val plan = table("a").select(star()) | ||
| assertEqual("/* This block comment surrounds a query which itself has a block comment...\n" + | ||
| "SELECT /* embedded single line */ 'embedded' AS x2;\n" + | ||
| "*/\n" + | ||
| "SELECT * FROM a", plan) | ||
| } | ||
|
|
||
| test("nexted bracketed comment case two") { | ||
|
Member
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. ditto
Contributor
Author
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. OK |
||
| val plan = table("a").select(star()) | ||
| assertEqual("SELECT -- continued after the following block comments...\n" + | ||
| "/* Deeply nested comment.\n" + | ||
| " This includes a single apostrophe to make sure we aren't decoding this part as a " + | ||
| "string.\n" + | ||
| "SELECT 'deep nest' AS n1;\n" + | ||
| "/* Second level of nesting...\n" + | ||
| "SELECT 'deeper nest' as n2;\n" + | ||
| "/* Third level of nesting...\n" + | ||
| "SELECT 'deepest nest' as n3;\n" + | ||
| "*/\n" + | ||
| "Hoo boy. Still two deep...\n" + | ||
| "*/\n" + | ||
| "Now just one deep...\n" + | ||
| "*/\n" + | ||
| "* FROM a", plan) | ||
| } | ||
|
cloud-fan marked this conversation as resolved.
|
||
|
|
||
| test("case insensitive") { | ||
| val plan = table("a").select(star()) | ||
| assertEqual("sELEct * FroM a", plan) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.