Skip to content

Commit

Permalink
Add more keywords as identifier in PPL (#1319)
Browse files Browse the repository at this point in the history
Signed-off-by: Peng Huo <penghuo@gmail.com>
  • Loading branch information
penghuo authored Feb 3, 2023
1 parent 513428b commit 79c7922
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
28 changes: 21 additions & 7 deletions ppl/src/main/antlr/OpenSearchPPLParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -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
;
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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()
));
}
}

0 comments on commit 79c7922

Please sign in to comment.