-
Notifications
You must be signed in to change notification settings - Fork 186
Support to parse backticks quoted identifiers #240
Support to parse backticks quoted identifiers #240
Conversation
…es that have been unquoted from the back-ticks
…rom the druid parser
...ava/com/amazon/opendistroforelasticsearch/sql/rewriter/identifier/UnquoteIdentifierRule.java
Show resolved
Hide resolved
...ava/com/amazon/opendistroforelasticsearch/sql/rewriter/identifier/UnquoteIdentifierRule.java
Show resolved
Hide resolved
} | ||
|
||
@Test | ||
public void backticksQuotedFieldNamesTest() { |
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.
Should we test so many queries within one method?
src/main/java/com/amazon/opendistroforelasticsearch/sql/utils/BackticksUnquoter.java
Outdated
Show resolved
Hide resolved
src/main/java/com/amazon/opendistroforelasticsearch/sql/utils/BackticksUnquoter.java
Outdated
Show resolved
Hide resolved
src/main/java/com/amazon/opendistroforelasticsearch/sql/utils/BackticksUnquoter.java
Outdated
Show resolved
Hide resolved
...est/java/com/amazon/opendistroforelasticsearch/sql/unittest/utils/BackticksUnquoterTest.java
Show resolved
Hide resolved
...est/java/com/amazon/opendistroforelasticsearch/sql/unittest/utils/BackticksUnquoterTest.java
Outdated
Show resolved
Hide resolved
...ava/com/amazon/opendistroforelasticsearch/sql/rewriter/identifier/UnquoteIdentifierRule.java
Outdated
Show resolved
Hide resolved
...ava/com/amazon/opendistroforelasticsearch/sql/rewriter/identifier/UnquoteIdentifierRule.java
Outdated
Show resolved
Hide resolved
...ava/com/amazon/opendistroforelasticsearch/sql/rewriter/identifier/UnquoteIdentifierRule.java
Outdated
Show resolved
Hide resolved
...ava/com/amazon/opendistroforelasticsearch/sql/rewriter/identifier/UnquoteIdentifierRule.java
Outdated
Show resolved
Hide resolved
...ava/com/amazon/opendistroforelasticsearch/sql/rewriter/identifier/UnquoteIdentifierRule.java
Show resolved
Hide resolved
...ava/com/amazon/opendistroforelasticsearch/sql/rewriter/identifier/UnquoteIdentifierRule.java
Outdated
Show resolved
Hide resolved
src/main/java/com/amazon/opendistroforelasticsearch/sql/utils/BackticksUnquoter.java
Outdated
Show resolved
Hide resolved
return unquotedStrBuilder.toString(); | ||
} | ||
|
||
public BackticksUnquoter() { |
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 don't need to instantiate this class, make constructor private
...est/java/com/amazon/opendistroforelasticsearch/sql/unittest/utils/BackticksUnquoterTest.java
Outdated
Show resolved
Hide resolved
… class, made corresponding changes for testing
...ava/com/amazon/opendistroforelasticsearch/sql/rewriter/identifier/UnquoteIdentifierRule.java
Show resolved
Hide resolved
src/main/java/com/amazon/opendistroforelasticsearch/sql/utils/StringUtils.java
Outdated
Show resolved
Hide resolved
src/main/java/com/amazon/opendistroforelasticsearch/sql/utils/StringUtils.java
Outdated
Show resolved
Hide resolved
src/main/java/com/amazon/opendistroforelasticsearch/sql/utils/StringUtils.java
Outdated
Show resolved
Hide resolved
src/main/java/com/amazon/opendistroforelasticsearch/sql/utils/StringUtils.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
public static boolean isQuoted(String text, String quote) { | ||
if (text != null && text.startsWith(quote) && text.endsWith(quote)) { |
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.
np: I would assume that if the text starts with a quote, then it has to end with a quote, otherwise the parser should have thrown exception before reaching to this method call.
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.
Also, just return the if condition expression in one line.
|
||
public class UnquoteIdentifierRule extends MySqlASTVisitorAdapter implements RewriteRule<SQLQueryExpr> { | ||
|
||
private String identifier = null; |
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 elaborate what is the use of this field variable? Because I feel this is risky to maintain global state between visit methods. Trying to understand its intent and see if other choice.
...ava/com/amazon/opendistroforelasticsearch/sql/rewriter/identifier/UnquoteIdentifierRule.java
Outdated
Show resolved
Hide resolved
src/test/java/com/amazon/opendistroforelasticsearch/sql/esintgtest/QueryIT.java
Show resolved
Hide resolved
…s-quoted identifier ITs into index test, field test, alias test
} | ||
|
||
@Test | ||
public void backticksQuotedAliasWithSpecialCharactersTest() { |
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.
Are there any other special characters that we should test against?
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.
Good point. I was wondering as well if there are any other special characters that would be generated by Tableau. But I think to support the space in alias is enough based on the other chars (eg. "_" etc.) that have been supported to pass the parse so far.
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.
SG
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.
LGTM. Could you do me a favor by adding one more case in your UT and IT for SELECT `bank`.`lastname` from `bank`
? This was the issue #213 I fixed earlier but unable to verify this case without your changes. Thanks!
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.
LGTM
Issue #, if available:
Issue #212 Tableau: Quoted identifiers not supported
Description of changes:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.