Skip to content

Commit 6e4855e

Browse files
committed
Support using timesnaps without quotes
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent f33eba7 commit 6e4855e

4 files changed

Lines changed: 15 additions & 8 deletions

File tree

docs/user/ppl/cmd/search.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Read more details on time modifiers `here <https://github.com/opensearch-project
7272
**Notes:**
7373

7474
* **Column name conflicts**: If your data contains columns named "earliest" or "latest", use backticks to access them as regular fields (e.g., ```earliest`="value"``) to avoid conflicts with time modifier syntax.
75-
* **Time snap syntax**: Time modifiers with time snaps must be wrapped in quotes (e.g., ``latest='+1d@d'``) for proper query parsing.
75+
* **Time snap syntax**: Time modifiers with chained time snaps must be wrapped in quotes (e.g., ``latest='+1d@month-10h@day'``) for proper query parsing.
7676

7777
Default Field Configuration
7878
===========================

integ-test/src/test/java/org/opensearch/sql/ppl/SearchCommandIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ public void testSearchWithChainedRelativeTimeRange() throws IOException {
952952
JSONObject result1 =
953953
executeQuery(
954954
String.format(
955-
"search source=%s earliest='2025-08-01 03:47:41' latest='+10months@year' | fields"
955+
"search source=%s earliest='2025-08-01 03:47:41' latest=+10months@year | fields"
956956
+ " @timestamp",
957957
TEST_INDEX_TIME_DATA));
958958
verifySchema(result1, schema("@timestamp", "timestamp"));

ppl/src/main/antlr/OpenSearchPPLLexer.g4

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ SINGLE_QUOTE: '\'';
227227
DOUBLE_QUOTE: '"';
228228
BACKTICK: '`';
229229
ARROW: '->';
230-
AT: '@';
230+
fragment AT: '@';
231231

232232
// Operators. Bit
233233

@@ -534,6 +534,15 @@ PERCENTILE_SHORTCUT: PERC(INTEGER_LITERAL | DECIMAL_LITERAL) | 'P
534534

535535
// LITERALS AND VALUES
536536
//STRING_LITERAL: DQUOTA_STRING | SQUOTA_STRING | BQUOTA_STRING;
537+
fragment TIME_SNAP_UNIT: S | SEC | SECOND
538+
| M | MIN | MINUTE
539+
| H | HR | HOUR | HOURS
540+
| D | DAY
541+
| W | WEEK
542+
| MON | MONTH
543+
| Q | QTR | QUARTER
544+
| Y | YR | YEAR;
545+
TIME_SNAP: AT TIME_SNAP_UNIT;
537546
ID: ID_LITERAL;
538547
CLUSTER: CLUSTER_PREFIX_LITERAL;
539548
INTEGER_LITERAL: DEC_DIGIT+;

ppl/src/main/antlr/OpenSearchPPLParser.g4

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -772,13 +772,10 @@ timeModifierValue
772772
| DECIMAL_LITERAL
773773
| INTEGER_LITERAL
774774
| stringLiteral
775-
| timeSnap
776-
| (PLUS | MINUS) (integerLiteral)? timeModifierUnit (timeSnap)?
775+
| TIME_SNAP
776+
| (PLUS | MINUS) (integerLiteral)? timeModifierUnit (TIME_SNAP)?
777777
;
778778

779-
timeSnap
780-
: AT timeModifierUnit;
781-
782779
// tables
783780
tableSource
784781
: tableQualifiedName
@@ -1360,6 +1357,7 @@ timespanUnit
13601357
| DS
13611358
;
13621359

1360+
// It differs from TIME_SNAP_UNIT in that it supports plural forms
13631361
timeModifierUnit
13641362
: S
13651363
| SEC

0 commit comments

Comments
 (0)