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

Parse backtick strings (``) as identifiers instead of string literals #678

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion legacy/src/main/antlr/OpenDistroSqlLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ COLON_SYMB: ':';
// Literal Primitives

START_NATIONAL_STRING_LITERAL: 'N' SQUOTA_STRING;
STRING_LITERAL: DQUOTA_STRING | SQUOTA_STRING | BQUOTA_STRING;
STRING_LITERAL: SQUOTA_STRING;
DECIMAL_LITERAL: DEC_DIGIT+;
HEXADECIMAL_LITERAL: 'X' '\'' (HEX_DIGIT HEX_DIGIT)+ '\''
| '0X' HEX_DIGIT+;
Expand All @@ -317,6 +317,8 @@ DOT_ID: '.' ID_LITERAL;
ID: ID_LITERAL;
// DOUBLE_QUOTE_ID: '"' ~'"'+ '"';
REVERSE_QUOTE_ID: '`' ~'`'+ '`';
DOUBLE_QUOTE_ID: DQUOTA_STRING;
BACKTICK_QUOTE_ID: BQUOTA_STRING;
STRING_USER_NAME: (
SQUOTA_STRING | DQUOTA_STRING
| BQUOTA_STRING | ID_LITERAL
Expand Down
3 changes: 2 additions & 1 deletion legacy/src/main/antlr/OpenDistroSqlParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ uid
simpleId
: ID
| DOT_ID // note: the current scope by adding DOT_ID to simpleId is large, move DOT_ID upwards tablename if needed
| STRING_LITERAL
| DOUBLE_QUOTE_ID
| BACKTICK_QUOTE_ID
| keywordsCanBeId
| functionNameBase
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,9 @@ public void queryWithBackticksQuotedFieldNameShouldPass() {
validate("SELECT s.`age` FROM semantics AS s");
validate("SELECT `s`.`age` FROM semantics AS `s`");
}

@Test
public void queryWithBackticksQuotedFieldNameInFunctionShouldPass() {
validate("SELECT SUM(`age`) FROM semantics");
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rupal-bq Added test

}