From 79c79220978e8edbcf8fc2ee02d7d55bde13dde4 Mon Sep 17 00:00:00 2001 From: Peng Huo Date: Fri, 3 Feb 2023 15:50:24 -0800 Subject: [PATCH] Add more keywords as identifier in PPL (#1319) Signed-off-by: Peng Huo --- ppl/src/main/antlr/OpenSearchPPLParser.g4 | 28 ++++++++++++++----- .../ppl/parser/AstExpressionBuilderTest.java | 27 ++++++++++++++++++ 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/ppl/src/main/antlr/OpenSearchPPLParser.g4 b/ppl/src/main/antlr/OpenSearchPPLParser.g4 index dbb63ef12a..80ffffb228 100644 --- a/ppl/src/main/antlr/OpenSearchPPLParser.g4 +++ b/ppl/src/main/antlr/OpenSearchPPLParser.g4 @@ -610,12 +610,26 @@ wildcard keywordsCanBeId : D // OD SQL and ODBC special - | statsFunctionName - | TIMESTAMP | DATE | TIME - | FIRST | LAST | timespanUnit | SPAN - | dateAndTimeFunctionBase - | textFunctionBase - | mathematicalFunctionBase - | positionFunctionName + | evalFunctionName + | relevanceArgName + | intervalUnit + // commands + | SEARCH | DESCRIBE | SHOW | FROM | WHERE | FIELDS | RENAME | STATS | DEDUP | SORT | EVAL | HEAD | TOP | RARE + | PARSE | METHOD | REGEX | PUNCT | GROK | PATTERN | PATTERNS | NEW_FIELD | KMEANS | AD | ML + // commands assist keywords + | SOURCE | INDEX | DESC | DATASOURCES + // CLAUSEKEYWORDS + | SORTBY + // FIELDKEYWORDSAUTO + | STR | IP | NUM + // ARGUMENT KEYWORDS + | KEEPEMPTY | CONSECUTIVE | DEDUP_SPLITVALUES | PARTITIONS | ALLNUM | DELIM | CENTROIDS | ITERATIONS | DISTANCE_TYPE + | NUMBER_OF_TREES | SHINGLE_SIZE | SAMPLE_SIZE | OUTPUT_AFTER | TIME_DECAY | ANOMALY_RATE | CATEGORY_FIELD + | TIME_FIELD | TIME_ZONE | TRAINING_DATA_SIZE | ANOMALY_SCORE_THRESHOLD + // AGGREGATIONS + | AVG | COUNT | DISTINCT_COUNT | ESTDC | ESTDC_ERROR | MAX | MEAN | MEDIAN | MIN | MODE | RANGE | STDEV | STDEVP + | SUM | SUMSQ | VAR_SAMP | VAR_POP | STDDEV_SAMP | STDDEV_POP | PERCENTILE | TAKE | FIRST | LAST | LIST | VALUES + | EARLIEST | EARLIEST_TIME | LATEST | LATEST_TIME | PER_DAY | PER_HOUR | PER_MINUTE | PER_SECOND | RATE | SPARKLINE + | C | DC ; diff --git a/ppl/src/test/java/org/opensearch/sql/ppl/parser/AstExpressionBuilderTest.java b/ppl/src/test/java/org/opensearch/sql/ppl/parser/AstExpressionBuilderTest.java index aa573449b6..16a6ff63b4 100644 --- a/ppl/src/test/java/org/opensearch/sql/ppl/parser/AstExpressionBuilderTest.java +++ b/ppl/src/test/java/org/opensearch/sql/ppl/parser/AstExpressionBuilderTest.java @@ -813,6 +813,11 @@ public void functionNameCanBeUsedAsIdentifier() { "ABS | CEIL | CEILING | CONV | CRC32 | E | EXP | FLOOR | LN | LOG" + " | LOG10 | LOG2 | MOD | PI |POW | POWER | RAND | ROUND | SIGN | SQRT | TRUNCATE " + "| ACOS | ASIN | ATAN | ATAN2 | COS | COT | DEGREES | RADIANS | SIN | TAN"); + assertFunctionNameCouldBeId( + "SEARCH | DESCRIBE | SHOW | FROM | WHERE | FIELDS | RENAME | STATS " + + "| DEDUP | SORT | EVAL | HEAD | TOP | RARE | PARSE | METHOD | REGEX | PUNCT | GROK " + + "| PATTERN | PATTERNS | NEW_FIELD | KMEANS | AD | ML | SOURCE | INDEX | D | DESC " + + "| DATASOURCES"); } void assertFunctionNameCouldBeId(String antlrFunctionName) { @@ -833,4 +838,26 @@ void assertFunctionNameCouldBeId(String antlrFunctionName) { )); } } + + // https://github.com/opensearch-project/sql/issues/1318 + @Test + public void indexCanBeId() { + assertEqual("source = index | stats count() by index", + agg( + relation("index"), + exprList( + alias( + "count()", + aggregate("count", AllFields.of()) + ) + ), + emptyList(), + exprList( + alias( + "index", + field("index") + )), + defaultStatsArgs() + )); + } }