From 58faa8c4f0f07d00d83647f4e6427967c7018395 Mon Sep 17 00:00:00 2001 From: Jordan Wilson Date: Tue, 11 Aug 2020 12:16:32 -0700 Subject: [PATCH 1/2] parse backticked strings as identifiers, instead of string literals --- legacy/src/main/antlr/OpenDistroSqlLexer.g4 | 4 +++- legacy/src/main/antlr/OpenDistroSqlParser.g4 | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/legacy/src/main/antlr/OpenDistroSqlLexer.g4 b/legacy/src/main/antlr/OpenDistroSqlLexer.g4 index af7e5eb0d0..6fdb8980a9 100644 --- a/legacy/src/main/antlr/OpenDistroSqlLexer.g4 +++ b/legacy/src/main/antlr/OpenDistroSqlLexer.g4 @@ -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+; @@ -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 diff --git a/legacy/src/main/antlr/OpenDistroSqlParser.g4 b/legacy/src/main/antlr/OpenDistroSqlParser.g4 index 86c5c89d20..2fa33864e7 100644 --- a/legacy/src/main/antlr/OpenDistroSqlParser.g4 +++ b/legacy/src/main/antlr/OpenDistroSqlParser.g4 @@ -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 ; From 2f94d8115d6a13aeb169a8d9240ef16544ea0502 Mon Sep 17 00:00:00 2001 From: Jordan Wilson Date: Tue, 11 Aug 2020 12:52:12 -0700 Subject: [PATCH 2/2] add test for quoted identifier in function call --- .../antlr/semantic/SemanticAnalyzerIdentifierTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/legacy/src/test/java/com/amazon/opendistroforelasticsearch/sql/legacy/antlr/semantic/SemanticAnalyzerIdentifierTest.java b/legacy/src/test/java/com/amazon/opendistroforelasticsearch/sql/legacy/antlr/semantic/SemanticAnalyzerIdentifierTest.java index 1ec2ff1f8a..a3e5d3f642 100644 --- a/legacy/src/test/java/com/amazon/opendistroforelasticsearch/sql/legacy/antlr/semantic/SemanticAnalyzerIdentifierTest.java +++ b/legacy/src/test/java/com/amazon/opendistroforelasticsearch/sql/legacy/antlr/semantic/SemanticAnalyzerIdentifierTest.java @@ -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"); + } }