Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Support to parse backticks quoted identifiers #240

Merged

Conversation

chloe-zh
Copy link
Member

Issue #, if available:

Issue #212 Tableau: Quoted identifiers not supported

Description of changes:

  1. Modified the semantic analyzer to unquote the index names and field names for the AST visitor, so that the identifiers would pass the new parser correctly.
  2. In the cases with back-ticks quoted identifiers, the AST is constructed improperly, so in this PR a rewriter rule is added to adjust the AST case by case.
  3. Added UT and IT.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

}

@Test
public void backticksQuotedFieldNamesTest() {
Copy link
Contributor

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?

return unquotedStrBuilder.toString();
}

public BackticksUnquoter() {
Copy link
Contributor

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

}

public static boolean isQuoted(String text, String quote) {
if (text != null && text.startsWith(quote) && text.endsWith(quote)) {
Copy link

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.

Copy link

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;
Copy link
Member

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.

}

@Test
public void backticksQuotedAliasWithSpecialCharactersTest() {
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SG

Copy link
Member

@dai-chen dai-chen left a 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!

@chloe-zh
Copy link
Member Author

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!

@dai-chen Yes, sure. Thanks!

Copy link
Contributor

@davidcui1225 davidcui1225 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chloe-zh chloe-zh merged commit 7fd35ea into opendistro-for-elasticsearch:master Oct 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants