-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Do not suppress candidate tokens in the middle of a rule #15085
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 |
|---|---|---|
|
|
@@ -99,9 +99,9 @@ private static Stream<Arguments> statements() | |
| Arguments.of("SELECT grouping(a+2) FROM (VALUES (1)) AS t (a) GROUP BY a+2", | ||
| "line 1:18: mismatched input '+'. Expecting: ')', ',', '.'"), | ||
| Arguments.of("SELECT x() over (ROWS select) FROM t", | ||
| "line 1:23: mismatched input 'select'. Expecting: 'BETWEEN', 'CURRENT', 'UNBOUNDED', <expression>"), | ||
| "line 1:23: mismatched input 'select'. Expecting: ')', 'BETWEEN', 'CURRENT', 'GROUPS', 'MEASURES', 'ORDER', 'PARTITION', 'RANGE', 'ROWS', 'UNBOUNDED', <expression>"), | ||
| Arguments.of("SELECT X() OVER (ROWS UNBOUNDED) FROM T", | ||
| "line 1:32: mismatched input ')'. Expecting: 'FOLLOWING', 'PRECEDING'"), | ||
| "line 1:32: mismatched input ')'. Expecting: '%', '(', '*', '+', '-', '->', '.', '/', 'AND', 'AT', 'FOLLOWING', 'OR', 'OVER', 'PRECEDING', '[', '||', <predicate>, <string>"), | ||
|
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. This doesn't seem right. The error position is reported as the end of The only valid tokens at that point are
Member
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. Yes, I know. I’m trying to figure out why it’s doing that. There’s some other bug lurking in there.
Member
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. It turns out these are all valid tokens per the grammar. It's because And For instance, this goes through the parser successfully even though it's clearly wrong if we consider It's treating
Member
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. If I mark
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. Is there a way to make the error handler treat
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. Another issue I can spot here is that the error handler suggests It is not correct, as position 23 is after the word
Member
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. It is correct (grammar-wise) because At the end of the day, this fixes a bug in the parser error handler that should've never existed in the initial implementation, so we should get it in. I can't think of any way to avoid the spurious tokens due to the non-reserved keyword handling without adding semantic knowledge to the grammar about the behavior of each rule, but I have some ideas that are out of the scope of this PR. |
||
| Arguments.of("SELECT a FROM x ORDER BY (SELECT b FROM t WHERE ", | ||
| "line 1:49: mismatched input '<EOF>'. Expecting: <expression>"), | ||
| Arguments.of("SELECT a FROM a AS x TABLESAMPLE x ", | ||
|
|
@@ -160,7 +160,13 @@ private static Stream<Arguments> statements() | |
| Arguments.of("SELECT * FROM t FOR TIMESTAMP AS OF TIMESTAMP WHERE", | ||
| "line 1:52: mismatched input '<EOF>'. Expecting: <expression>"), | ||
| Arguments.of("SELECT * FROM t FOR VERSION AS OF TIMESTAMP WHERE", | ||
| "line 1:50: mismatched input '<EOF>'. Expecting: <expression>")); | ||
| "line 1:50: mismatched input '<EOF>'. Expecting: <expression>"), | ||
| Arguments.of("SELECT ROW(DATE '2022-10-10', DOUBLE 12.0)", | ||
|
martint marked this conversation as resolved.
Outdated
martint marked this conversation as resolved.
Outdated
|
||
| "line 1:38: mismatched input '12.0'. Expecting: '%', '(', ')', '*', '+', ',', '-', '->', '.', '/', 'AND', 'AT', 'OR', 'ORDER', 'OVER', 'PRECISION', '[', '||', <predicate>, <string>"), | ||
| Arguments.of("VALUES(DATE 2)", | ||
| "line 1:13: mismatched input '2'. Expecting: '%', '(', ')', '*', '+', ',', '-', '->', '.', '/', 'AND', 'AT', 'OR', 'OVER', '[', '||', <predicate>, <string>"), | ||
| Arguments.of("SELECT count(DISTINCT *) FROM (VALUES 1)", | ||
| "line 1:23: mismatched input '*'. Expecting: <expression>")); | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -178,7 +184,7 @@ public void testPossibleExponentialBacktracking() | |
| "1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * " + | ||
| "1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9 * " + | ||
| "1 * 2 * 3 * 4 * 5 * 6 * 7 * 8 * 9", | ||
| "line 1:375: mismatched input '<EOF>'. Expecting: '%', '*', '+', '-', '/', 'AT', 'THEN', '||'"); | ||
| "line 1:375: mismatched input '<EOF>'. Expecting: '%', '*', '+', '-', '.', '/', 'AND', 'AT', 'OR', 'THEN', '[', '||', <predicate>"); | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -208,7 +214,7 @@ public void testPossibleExponentialBacktracking2() | |
| "OR (f()\n" + | ||
| "OR (f()\n" + | ||
| "GROUP BY id", | ||
| "line 24:1: mismatched input 'GROUP'. Expecting: ')', ',', '.', 'FILTER', 'IGNORE', 'OVER', 'RESPECT', '['"); | ||
| "line 24:1: mismatched input 'GROUP'. Expecting: '%', ')', '*', '+', ',', '-', '.', '/', 'AND', 'AT', 'FILTER', 'IGNORE', 'OR', 'OVER', 'RESPECT', '[', '||', <predicate>"); | ||
| } | ||
|
|
||
| @ParameterizedTest | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we can remove
ignoredRulefromErrorHandlernow?AFAIK,
nonReservedwas the only ignored rule.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we can remove that.