Skip to content
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
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()
));
}
}