Skip to content

Commit d0d142f

Browse files
committed
Update explain IT for search with time modifier
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent 099c31b commit d0d142f

16 files changed

Lines changed: 106 additions & 16 deletions

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

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ public void testExplainOnAggregationWithFunction() throws IOException {
639639

640640
@Test
641641
public void testSearchCommandWithAbsoluteTimeRange() throws IOException {
642-
String expected = loadExpectedPlan("explain_search_with_absolute_time_range.yaml");
642+
String expected = loadExpectedPlan("search_with_absolute_time_range.yaml");
643643
assertYamlEqualsJsonIgnoreId(
644644
expected,
645645
explainQueryToString(
@@ -650,34 +650,34 @@ public void testSearchCommandWithAbsoluteTimeRange() throws IOException {
650650

651651
@Test
652652
public void testSearchCommandWithRelativeTimeRange() throws IOException {
653-
String expected = loadExpectedPlan("explain_search_with_relative_time_range.yaml");
654653
assertYamlEqualsJsonIgnoreId(
655-
expected,
654+
loadExpectedPlan("search_with_relative_time_range.yaml"),
655+
// "",
656+
explainQueryToString(
657+
String.format("source=%s earliest=-1q latest=+30d", TEST_INDEX_TIME_DATA)));
658+
659+
assertYamlEqualsJsonIgnoreId(
660+
loadExpectedPlan("search_with_relative_time_snap.yaml"),
656661
explainQueryToString(
657662
String.format("source=%s earliest='-1q@year' latest=now", TEST_INDEX_TIME_DATA)));
658663
}
659664

660665
@Test
661666
public void testSearchCommandWithNumericTimeRange() throws IOException {
662-
String expected = loadExpectedPlan("explain_search_with_numeric_time_range.yaml");
667+
String expected = loadExpectedPlan("search_with_numeric_time_range.yaml");
663668
assertYamlEqualsJsonIgnoreId(
664669
expected,
665670
explainQueryToString(
666671
String.format("source=%s earliest=1 latest=1754020061.123456", TEST_INDEX_TIME_DATA)));
667672
}
668673

669-
protected String loadExpectedPlan(String fileName) throws IOException {
670-
String prefix;
671-
if (isCalciteEnabled()) {
672-
if (isPushdownDisabled()) {
673-
prefix = "expectedOutput/calcite_no_pushdown/";
674-
} else {
675-
prefix = "expectedOutput/calcite/";
676-
}
677-
} else {
678-
prefix = "expectedOutput/ppl/";
679-
}
680-
return loadFromFile(prefix + fileName);
674+
@Test
675+
public void testSearchCommandWithChainedTimeModifier() throws IOException {
676+
assertYamlEqualsJsonIgnoreId(
677+
loadExpectedPlan("search_with_chained_time_modifier.yaml"),
678+
explainQueryToString(
679+
String.format(
680+
"source=%s earliest='-3d@d-2h+10m' latest='-1d+1y@mon'", TEST_INDEX_TIME_DATA)));
681681
}
682682

683683
// Search command explain examples - 3 core use cases
@@ -710,4 +710,18 @@ public void testExplainSearchWildcardStar() throws IOException {
710710
explainQueryToString(
711711
String.format("search source=%s severityText=ERR*", TEST_INDEX_OTEL_LOGS)));
712712
}
713+
714+
protected String loadExpectedPlan(String fileName) throws IOException {
715+
String prefix;
716+
if (isCalciteEnabled()) {
717+
if (isPushdownDisabled()) {
718+
prefix = "expectedOutput/calcite_no_pushdown/";
719+
} else {
720+
prefix = "expectedOutput/calcite/";
721+
}
722+
} else {
723+
prefix = "expectedOutput/ppl/";
724+
}
725+
return loadFromFile(prefix + fileName);
726+
}
713727
}

integ-test/src/test/resources/expectedOutput/calcite/explain_search_with_absolute_time_range.yaml renamed to integ-test/src/test/resources/expectedOutput/calcite/search_with_absolute_time_range.yaml

File renamed without changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
calcite:
2+
logical: |
3+
LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT])
4+
LogicalProject(@timestamp=[$0], category=[$1], value=[$2], timestamp=[$3])
5+
LogicalFilter(condition=[query_string(MAP('query', '(@timestamp:>=now\-3d\/d\-2h\+10m) AND (@timestamp:<=now\-1d\+1y\/M)':VARCHAR))])
6+
CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_time_data]])
7+
physical: |
8+
CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_time_data]], PushDownContext=[[PROJECT->[@timestamp, category, value, timestamp], FILTER->query_string(MAP('query', '(@timestamp:>=now\-3d\/d\-2h\+10m) AND (@timestamp:<=now\-1d\+1y\/M)':VARCHAR)), LIMIT->10000], OpenSearchRequestBuilder(sourceBuilder={"from":0,"size":10000,"timeout":"1m","query":{"query_string":{"query":"(@timestamp:>=now\\-3d\\/d\\-2h\\+10m) AND (@timestamp:<=now\\-1d\\+1y\\/M)","fields":[],"type":"best_fields","default_operator":"or","max_determinized_states":10000,"enable_position_increments":true,"fuzziness":"AUTO","fuzzy_prefix_length":0,"fuzzy_max_expansions":50,"phrase_slop":0,"escape":false,"auto_generate_synonyms_phrase_query":true,"fuzzy_transpositions":true,"boost":1.0}},"_source":{"includes":["@timestamp","category","value","timestamp"],"excludes":[]},"sort":[{"_doc":{"order":"asc"}}]}, requestedTotalSize=10000, pageSize=null, startFrom=0)])

integ-test/src/test/resources/expectedOutput/calcite/explain_search_with_numeric_time_range.yaml renamed to integ-test/src/test/resources/expectedOutput/calcite/search_with_numeric_time_range.yaml

File renamed without changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
calcite:
2+
logical: |
3+
LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT])
4+
LogicalProject(@timestamp=[$0], category=[$1], value=[$2], timestamp=[$3])
5+
LogicalFilter(condition=[query_string(MAP('query', '(@timestamp:>=now\-3M) AND (@timestamp:<=now\+30d)':VARCHAR))])
6+
CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_time_data]])
7+
physical: |
8+
CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_time_data]], PushDownContext=[[PROJECT->[@timestamp, category, value, timestamp], FILTER->query_string(MAP('query', '(@timestamp:>=now\-3M) AND (@timestamp:<=now\+30d)':VARCHAR)), LIMIT->10000], OpenSearchRequestBuilder(sourceBuilder={"from":0,"size":10000,"timeout":"1m","query":{"query_string":{"query":"(@timestamp:>=now\\-3M) AND (@timestamp:<=now\\+30d)","fields":[],"type":"best_fields","default_operator":"or","max_determinized_states":10000,"enable_position_increments":true,"fuzziness":"AUTO","fuzzy_prefix_length":0,"fuzzy_max_expansions":50,"phrase_slop":0,"escape":false,"auto_generate_synonyms_phrase_query":true,"fuzzy_transpositions":true,"boost":1.0}},"_source":{"includes":["@timestamp","category","value","timestamp"],"excludes":[]},"sort":[{"_doc":{"order":"asc"}}]}, requestedTotalSize=10000, pageSize=null, startFrom=0)])

integ-test/src/test/resources/expectedOutput/calcite/explain_search_with_relative_time_range.yaml renamed to integ-test/src/test/resources/expectedOutput/calcite/search_with_relative_time_snap.yaml

File renamed without changes.

integ-test/src/test/resources/expectedOutput/calcite_no_pushdown/explain_search_with_absolute_time_range.yaml renamed to integ-test/src/test/resources/expectedOutput/calcite_no_pushdown/search_with_absolute_time_range.yaml

File renamed without changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
calcite:
2+
logical: |
3+
LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT])
4+
LogicalProject(@timestamp=[$0], category=[$1], value=[$2], timestamp=[$3])
5+
LogicalFilter(condition=[query_string(MAP('query', '(@timestamp:>=now\-3d\/d\-2h\+10m) AND (@timestamp:<=now\-1d\+1y\/M)':VARCHAR))])
6+
CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_time_data]])
7+
physical: |
8+
EnumerableLimit(fetch=[10000])
9+
EnumerableCalc(expr#0..9=[{inputs}], proj#0..3=[{exprs}])
10+
CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_time_data]], PushDownContext=[[FILTER->query_string(MAP('query', '(@timestamp:>=now\-3d\/d\-2h\+10m) AND (@timestamp:<=now\-1d\+1y\/M)':VARCHAR))], OpenSearchRequestBuilder(sourceBuilder={"from":0,"timeout":"1m","query":{"query_string":{"query":"(@timestamp:>=now\\-3d\\/d\\-2h\\+10m) AND (@timestamp:<=now\\-1d\\+1y\\/M)","fields":[],"type":"best_fields","default_operator":"or","max_determinized_states":10000,"enable_position_increments":true,"fuzziness":"AUTO","fuzzy_prefix_length":0,"fuzzy_max_expansions":50,"phrase_slop":0,"escape":false,"auto_generate_synonyms_phrase_query":true,"fuzzy_transpositions":true,"boost":1.0}},"sort":[{"_doc":{"order":"asc"}}]}, requestedTotalSize=2147483647, pageSize=null, startFrom=0)])

integ-test/src/test/resources/expectedOutput/calcite_no_pushdown/explain_search_with_numeric_time_range.yaml renamed to integ-test/src/test/resources/expectedOutput/calcite_no_pushdown/search_with_numeric_time_range.yaml

File renamed without changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
calcite:
2+
logical: |
3+
LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT])
4+
LogicalProject(@timestamp=[$0], category=[$1], value=[$2], timestamp=[$3])
5+
LogicalFilter(condition=[query_string(MAP('query', '(@timestamp:>=now\-3M) AND (@timestamp:<=now\+30d)':VARCHAR))])
6+
CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_time_data]])
7+
physical: |
8+
EnumerableLimit(fetch=[10000])
9+
EnumerableCalc(expr#0..9=[{inputs}], proj#0..3=[{exprs}])
10+
CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_time_data]], PushDownContext=[[FILTER->query_string(MAP('query', '(@timestamp:>=now\-3M) AND (@timestamp:<=now\+30d)':VARCHAR))], OpenSearchRequestBuilder(sourceBuilder={"from":0,"timeout":"1m","query":{"query_string":{"query":"(@timestamp:>=now\\-3M) AND (@timestamp:<=now\\+30d)","fields":[],"type":"best_fields","default_operator":"or","max_determinized_states":10000,"enable_position_increments":true,"fuzziness":"AUTO","fuzzy_prefix_length":0,"fuzzy_max_expansions":50,"phrase_slop":0,"escape":false,"auto_generate_synonyms_phrase_query":true,"fuzzy_transpositions":true,"boost":1.0}},"sort":[{"_doc":{"order":"asc"}}]}, requestedTotalSize=2147483647, pageSize=null, startFrom=0)])

0 commit comments

Comments
 (0)