Skip to content
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

Allow common keywords and scalar function name used as identifier #1191

Merged
merged 3 commits into from
Jan 3, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public void hasGroupKeyMaxAddLiteralShouldPass() {
rows("f", 1));
}

@Ignore("Handled by v2 engine which returns 'name': 'Log(MAX(age) + MIN(age))' instead")
MaxKsyunz marked this conversation as resolved.
Show resolved Hide resolved
@Test
public void noGroupKeyLogMaxAddMinShouldPass() {
JSONObject response = executeJdbcRequest(String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ public void functionWithoutAliasShouldHaveEntireFunctionAsNameInSchema() {
);
}

@Ignore("Handled by v2 engine which returns 'name': 'substring(lastname, 1, 2)' instead")
dai-chen marked this conversation as resolved.
Show resolved Hide resolved
@Test
public void functionWithAliasShouldHaveAliasAsNameInSchema() {
assertThat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ SELECT VAR_SAMP(AvgTicketPrice) FROM opensearch_dashboards_sample_data_flights
SELECT STDDEV_POP(AvgTicketPrice) FROM opensearch_dashboards_sample_data_flights
SELECT STDDEV_SAMP(AvgTicketPrice) FROM opensearch_dashboards_sample_data_flights
SELECT COUNT(DISTINCT Origin), COUNT(DISTINCT Dest) FROM opensearch_dashboards_sample_data_flights
SELECT COUNT(DISTINCT Origin) FROM (SELECT * FROM opensearch_dashboards_sample_data_flights) AS flights
SELECT COUNT(DISTINCT Origin) FROM (SELECT * FROM opensearch_dashboards_sample_data_flights) AS flights
SELECT LOG(MAX(AvgTicketPrice) + MIN(AvgTicketPrice)) FROM opensearch_dashboards_sample_data_flights
68 changes: 0 additions & 68 deletions sql/src/main/antlr/OpenSearchSQLIdentifierParser.g4

This file was deleted.

36 changes: 34 additions & 2 deletions sql/src/main/antlr/OpenSearchSQLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ THE SOFTWARE.

parser grammar OpenSearchSQLParser;

import OpenSearchSQLIdentifierParser;

options { tokenVocab=OpenSearchSQLLexer; }


Expand Down Expand Up @@ -561,3 +559,37 @@ alternateMultiMatchField
| argName=alternateMultiMatchArgName EQUAL_SYMBOL
LT_SQR_PRTHS argVal=relevanceArgValue RT_SQR_PRTHS
;


// Identifiers

tableName
: qualifiedName
;

columnName
: qualifiedName
;

alias
: ident
;

qualifiedName
: ident (DOT ident)*
;

ident
: DOT? ID
| BACKTICK_QUOTE_ID
| keywordsCanBeId
| scalarFunctionName
;

keywordsCanBeId
: FULL
| FIELD | D | T | TS // OD SQL and ODBC special
| COUNT | SUM | AVG | MAX | MIN
| FIRST | LAST
| TYPE // TODO: Type is keyword required by relevancy function. Remove this when relevancy functions moved out
;
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public void canBuildQualifiedIdentifier() {
buildFromQualifiers("account.location.city").expectQualifiedName("account", "location", "city");
}

@Test
public void commonKeywordCanBeUsedAsIdentifier() {
buildFromIdentifier("type").expectQualifiedName("type");
}

@Test
public void functionNameCanBeUsedAsIdentifier() {
Expand Down