Skip to content

Commit 79c7922

Browse files
authored
Add more keywords as identifier in PPL (#1319)
Signed-off-by: Peng Huo <[email protected]>
1 parent 513428b commit 79c7922

File tree

2 files changed

+48
-7
lines changed

2 files changed

+48
-7
lines changed

ppl/src/main/antlr/OpenSearchPPLParser.g4

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -610,12 +610,26 @@ wildcard
610610

611611
keywordsCanBeId
612612
: D // OD SQL and ODBC special
613-
| statsFunctionName
614-
| TIMESTAMP | DATE | TIME
615-
| FIRST | LAST
616613
| timespanUnit | SPAN
617-
| dateAndTimeFunctionBase
618-
| textFunctionBase
619-
| mathematicalFunctionBase
620-
| positionFunctionName
614+
| evalFunctionName
615+
| relevanceArgName
616+
| intervalUnit
617+
// commands
618+
| SEARCH | DESCRIBE | SHOW | FROM | WHERE | FIELDS | RENAME | STATS | DEDUP | SORT | EVAL | HEAD | TOP | RARE
619+
| PARSE | METHOD | REGEX | PUNCT | GROK | PATTERN | PATTERNS | NEW_FIELD | KMEANS | AD | ML
620+
// commands assist keywords
621+
| SOURCE | INDEX | DESC | DATASOURCES
622+
// CLAUSEKEYWORDS
623+
| SORTBY
624+
// FIELDKEYWORDSAUTO
625+
| STR | IP | NUM
626+
// ARGUMENT KEYWORDS
627+
| KEEPEMPTY | CONSECUTIVE | DEDUP_SPLITVALUES | PARTITIONS | ALLNUM | DELIM | CENTROIDS | ITERATIONS | DISTANCE_TYPE
628+
| NUMBER_OF_TREES | SHINGLE_SIZE | SAMPLE_SIZE | OUTPUT_AFTER | TIME_DECAY | ANOMALY_RATE | CATEGORY_FIELD
629+
| TIME_FIELD | TIME_ZONE | TRAINING_DATA_SIZE | ANOMALY_SCORE_THRESHOLD
630+
// AGGREGATIONS
631+
| AVG | COUNT | DISTINCT_COUNT | ESTDC | ESTDC_ERROR | MAX | MEAN | MEDIAN | MIN | MODE | RANGE | STDEV | STDEVP
632+
| SUM | SUMSQ | VAR_SAMP | VAR_POP | STDDEV_SAMP | STDDEV_POP | PERCENTILE | TAKE | FIRST | LAST | LIST | VALUES
633+
| EARLIEST | EARLIEST_TIME | LATEST | LATEST_TIME | PER_DAY | PER_HOUR | PER_MINUTE | PER_SECOND | RATE | SPARKLINE
634+
| C | DC
621635
;

ppl/src/test/java/org/opensearch/sql/ppl/parser/AstExpressionBuilderTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,11 @@ public void functionNameCanBeUsedAsIdentifier() {
813813
"ABS | CEIL | CEILING | CONV | CRC32 | E | EXP | FLOOR | LN | LOG"
814814
+ " | LOG10 | LOG2 | MOD | PI |POW | POWER | RAND | ROUND | SIGN | SQRT | TRUNCATE "
815815
+ "| ACOS | ASIN | ATAN | ATAN2 | COS | COT | DEGREES | RADIANS | SIN | TAN");
816+
assertFunctionNameCouldBeId(
817+
"SEARCH | DESCRIBE | SHOW | FROM | WHERE | FIELDS | RENAME | STATS "
818+
+ "| DEDUP | SORT | EVAL | HEAD | TOP | RARE | PARSE | METHOD | REGEX | PUNCT | GROK "
819+
+ "| PATTERN | PATTERNS | NEW_FIELD | KMEANS | AD | ML | SOURCE | INDEX | D | DESC "
820+
+ "| DATASOURCES");
816821
}
817822

818823
void assertFunctionNameCouldBeId(String antlrFunctionName) {
@@ -833,4 +838,26 @@ void assertFunctionNameCouldBeId(String antlrFunctionName) {
833838
));
834839
}
835840
}
841+
842+
// https://github.com/opensearch-project/sql/issues/1318
843+
@Test
844+
public void indexCanBeId() {
845+
assertEqual("source = index | stats count() by index",
846+
agg(
847+
relation("index"),
848+
exprList(
849+
alias(
850+
"count()",
851+
aggregate("count", AllFields.of())
852+
)
853+
),
854+
emptyList(),
855+
exprList(
856+
alias(
857+
"index",
858+
field("index")
859+
)),
860+
defaultStatsArgs()
861+
));
862+
}
836863
}

0 commit comments

Comments
 (0)