Skip to content

Commit 1cdc7e4

Browse files
committed
Support now() in time range
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 8611075 commit 1cdc7e4

3 files changed

Lines changed: 19 additions & 5 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,9 @@ public void testSearchCommandWithAbsoluteTimeRange() throws IOException {
644644
public void testSearchCommandWithRelativeTimeRange() throws IOException {
645645
String expected = loadExpectedPlan("explain_search_with_relative_time_range.json");
646646
assertJsonEqualsIgnoreId(
647-
expected,
648-
explainQueryToString(String.format("source=%s earliest='-1q@year' latest=now", TEST_INDEX_TIME_DATA)));
647+
expected,
648+
explainQueryToString(
649+
String.format("source=%s earliest='-1q@year' latest=now", TEST_INDEX_TIME_DATA)));
649650
}
650651

651652
protected String loadExpectedPlan(String fileName) throws IOException {

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -923,19 +923,19 @@ public void testSearchWithDateINOperator() throws IOException {
923923
}
924924

925925
@Test
926-
public void testSearchWithEarliest() throws IOException {
926+
public void testSearchWithAbsoluteEarliestAndNow() throws IOException {
927927
JSONObject result1 =
928928
executeQuery(
929929
String.format(
930-
"search source=%s earliest='2025-08-01 03:47:41' | fields @timestamp",
930+
"search source=%s earliest='2025-08-01 03:47:41' latest=now | fields @timestamp",
931931
TEST_INDEX_TIME_DATA));
932932
verifySchema(result1, schema("@timestamp", "timestamp"));
933933
verifyDataRows(result1, rows("2025-08-01 03:47:41"));
934934

935935
JSONObject result0 =
936936
executeQuery(
937937
String.format(
938-
"search source=%s earliest='2025-08-01 03:47:42' | fields @timestamp",
938+
"search source=%s earliest='2025-08-01 03:47:42' latest=now() | fields @timestamp",
939939
TEST_INDEX_TIME_DATA));
940940
verifyNumOfRows(result0, 0);
941941

@@ -946,4 +946,16 @@ public void testSearchWithEarliest() throws IOException {
946946
TEST_INDEX_TIME_DATA));
947947
verifyDataRows(result2, rows("2025-08-01 02:00:56"), rows("2025-08-01 03:47:41"));
948948
}
949+
950+
@Test
951+
public void testSearchWithChainedRelativeTimeRange() throws IOException {
952+
JSONObject result1 =
953+
executeQuery(
954+
String.format(
955+
"search source=%s earliest='2025-08-01 03:47:41' latest='+10months@year' | fields"
956+
+ " @timestamp",
957+
TEST_INDEX_TIME_DATA));
958+
verifySchema(result1, schema("@timestamp", "timestamp"));
959+
verifyDataRows(result1, rows("2025-08-01 03:47:41"));
960+
}
949961
}

ppl/src/main/antlr/OpenSearchPPLParser.g4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,7 @@ timeModifier
763763

764764
timeModifierValue
765765
: NOW
766+
| NOW LT_PRTHS RT_PRTHS
766767
| stringLiteral
767768
| timeSnap
768769
| (PLUS | MINUS) (integerLiteral)? timeModifierUnit (timeSnap)?

0 commit comments

Comments
 (0)