-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-31950][SQL][TESTS] Extract SQL keywords from the SqlBase.g4 file #28802
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
Conversation
| // The non-reserved keywords are listed in `nonReserved`. | ||
| // These 2 together contain all the keywords. | ||
| strictNonReserved | ||
| //--ANSI-STRICT-NON-RESERVED-START |
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.
this is not ansi, we should just call it STRICT-NON-RESERVED
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.
oh, I missed that. I'll update soon.
| val nonReservedKeywordsInAnsiMode = parseSyntax( | ||
| "//--ANSI-NON-RESERVED-START", "//--ANSI-NON-RESERVED-END") | ||
|
|
||
| val reservedKeywordsInAnsiMode = { |
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.
ansi reserved keywords are "full keywords -- non-reserved keywords".
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.
"non-reserved keywords" means non-reserved keywords in ansi + strict non-reserved keywords?
Does previous allCandidateKeywords include strict non-reserved keywords?
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.
okay, fixed.
|
Test build #123860 has finished for PR 28802 at commit
|
| private val sqlSyntaxDefs = { | ||
| val sqlBasePath = { | ||
| val sparkHome = { | ||
| assert(sys.props.contains("spark.test.home") || |
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.
@maropu Minor Nit. I was trying to run this and i didn't have the environment variable set. The error message ends up printing the full env info making it difficult to find what the error is ? Should we use something like:
if (condition) {
fail(...)
}
or may be there is a better way :-).
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.
Thanks for the check, @dilipbiswal . SQLQueryTestSuite has the same logic, so I personally think its better to fix them at the same time. https://github.com/apache/spark/blob/master/sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala#L132
Could you make a PR after this merged?
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.
@maropu Sure.. will do.
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.
Thanks!
| if (line.trim.startsWith(startTag)) { | ||
| start = true | ||
| } else if (line.trim.startsWith(endTag)) { | ||
| start = false |
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.
nit: Just return once reaching endTag?
| "//--ANSI-NON-RESERVED-START", "//--ANSI-NON-RESERVED-END") | ||
|
|
||
| val nonReservedKeywordsInAnsiMode = allCandidateKeywords -- reservedKeywordsInAnsiMode | ||
| val reservedKeywordsInAnsiMode = allCandidateKeywords -- nonReservedKeywordsInAnsiMode |
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.
If we remove the tags, will the related tests fail? I have this question because these tests seems do foreach on these lists. If we remove the tags and get an empty list, seems the tests won't fail too?
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.
Ah, nice suggestion. In that case, the tests should fail. I'll check and update.
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.
Could you check the latest commit? Is that okay to you?
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.
Yeah, thanks. Looks good.
| } | ||
|
|
||
| val nonReservedKeywordsInAnsiMode = allCandidateKeywords -- reservedKeywordsInAnsiMode | ||
| private def parseSyntax(startTag: String, endTag: String): Set[String] = { |
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.
nit: it's only used once, can we inline it?
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.
Ah, right. okay.
|
Test build #123871 has finished for PR 28802 at commit
|
...atalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/TableIdentifierParserSuite.scala
Show resolved
Hide resolved
|
Test build #123874 has finished for PR 28802 at commit
|
|
Test build #123891 has finished for PR 28802 at commit
|
|
Test build #123892 has finished for PR 28802 at commit
|
|
Test build #123876 has finished for PR 28802 at commit
|
|
Test build #123905 has finished for PR 28802 at commit
|
|
Thanks! Merged to master. |
### What changes were proposed in this pull request? This PR intends to extract SQL reserved/non-reserved keywords from the ANTLR grammar file (`SqlBase.g4`) directly. This approach is based on the cloud-fan suggestion: #28779 (comment) ### Why are the changes needed? It is hard to maintain a full set of the keywords in `TableIdentifierParserSuite`, so it would be nice if we could extract them from the `SqlBase.g4` file directly. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Existing tests. Closes #28802 from maropu/SPARK-31950-2. Authored-by: Takeshi Yamamuro <[email protected]> Signed-off-by: Takeshi Yamamuro <[email protected]>
### What changes were proposed in this pull request? This PR intends to extract SQL reserved/non-reserved keywords from the ANTLR grammar file (`SqlBase.g4`) directly. This approach is based on the cloud-fan suggestion: apache#28779 (comment) ### Why are the changes needed? It is hard to maintain a full set of the keywords in `TableIdentifierParserSuite`, so it would be nice if we could extract them from the `SqlBase.g4` file directly. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Existing tests. Closes apache#28802 from maropu/SPARK-31950-2. Authored-by: Takeshi Yamamuro <[email protected]> Signed-off-by: Takeshi Yamamuro <[email protected]>
What changes were proposed in this pull request?
This PR intends to extract SQL reserved/non-reserved keywords from the ANTLR grammar file (
SqlBase.g4) directly.This approach is based on the @cloud-fan suggestion: #28779 (comment)
Why are the changes needed?
It is hard to maintain a full set of the keywords in
TableIdentifierParserSuite, so it would be nice if we could extract them from theSqlBase.g4file directly.Does this PR introduce any user-facing change?
No.
How was this patch tested?
Existing tests.