-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[CALCITE-7121] Allow to use hyphens in unquoted Table Names in dialects with backticks quoting #4487
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
base: main
Are you sure you want to change the base?
[CALCITE-7121] Allow to use hyphens in unquoted Table Names in dialects with backticks quoting #4487
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -987,6 +987,25 @@ private void checkLarge(int n) { | |
| .fails("(?s)Encountered \"-\" at .*") | ||
| .withDialect(BIG_QUERY) | ||
| .fails("(?s)Encountered \"-\" at .*"); | ||
|
|
||
| final SqlConformance nonBigQueryConformance = new SqlAbstractConformance() { | ||
| @Override public boolean allowHyphenInUnquotedTableName() { | ||
| return true; | ||
| } | ||
| }; | ||
|
|
||
| sql("select * from foo-bar.baz cross join (select alpha-omega from t) as t") | ||
| .withDialect(MYSQL) | ||
|
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. mysql was picked here since it has backticks
Contributor
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 test and the one following it look identical. Yet one is supposed to succeed and the other to fail. How does that work?
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 updated tests to have same as for BigQuery |
||
| .withConformance(nonBigQueryConformance) | ||
| .ok("SELECT *\n" | ||
| + "FROM `foo-bar`.`baz`\n" | ||
| + "CROSS JOIN (SELECT (`alpha` - `omega`)\n" | ||
| + "FROM `t`) AS `t`"); | ||
|
|
||
| sql("select * from foo ^-^ bar.baz cross join (select alpha-omega from t) as t") | ||
| .withDialect(MYSQL) | ||
| .withConformance(nonBigQueryConformance) | ||
| .fails("(?s)Encountered \"-\" at .*"); | ||
| } | ||
|
|
||
| @Test void testHyphenatedColumnName() { | ||
|
|
||
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.
With this change, any dialect whose
allowHyphenInUnquotedTableNamereturns true will allow identifiers with back-ticks. I don't think anyone will expect that.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.
then it is not clear what is the purpose of
allowHyphenInUnquotedTableNamereturningtruethen?Isn't this what is meant in javadoc
calcite/core/src/main/java/org/apache/calcite/sql/validate/SqlConformance.java
Lines 247 to 250 in 2fafa52
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.
Well, suppose someone has asked for Oracle-style quoted identifiers,
"my table". If they also makeallowHyphenInUnquotedTableNamereturn true then they aren't going to get the parser behavior that they asked for.Uh oh!
There was an error while loading. Please reload this page.
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, same happens without this PR changes, and makes me thinking that javadoc doesn't reflect current behavior...
Initially (also put in jira description) I was thinking to make it working for backticks quoting only.
Do you think it would make sense to make it working for all (asking since so far I don't know other well known DB vendors supporting this)
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.
You should take the time to understand how it currently works. The implementation is subtle.
Lexical states are a very clever tool (I introduced them myself, to allow switching between quoting styles) but they are costly. Each lexical state creates a whole new copy of the parser's transition table and therefore makes the parser much larger.
Therefore we should only support the combinations that people actually need.
Relying on the sets of literal styles to deduce that we are dealing with BigQuery was a hack on my part. (See https://issues.apache.org/jira/browse/CALCITE-4247.) But that doesn't give you license to make the hack worse. In fact, if you want to change things, you have to figure out a way to make things better.