Skip to content

Commit d2a95ea

Browse files
committed
Merge branch 'main' into rexnode-json-serialization
2 parents fde5cf0 + 0b4423e commit d2a95ea

File tree

8 files changed

+288
-175
lines changed

8 files changed

+288
-175
lines changed

integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteExplainIT.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static org.opensearch.sql.util.MatcherUtils.assertJsonEqualsIgnoreId;
99

1010
import java.io.IOException;
11+
import org.junit.Assume;
1112
import org.junit.Ignore;
1213
import org.junit.Test;
1314
import org.opensearch.sql.ppl.ExplainIT;
@@ -68,6 +69,32 @@ public void supportPushDownSortMergeJoin() throws IOException {
6869
assertJsonEqualsIgnoreId(expected, result);
6970
}
7071

72+
// Only for Calcite
73+
@Test
74+
public void supportPartialPushDown() throws IOException {
75+
Assume.assumeTrue("This test is only for push down enabled", isPushdownEnabled());
76+
// field `address` is text type without keyword subfield, so we cannot push it down.
77+
String query =
78+
"source=opensearch-sql_test_index_account | where (state = 'Seattle' or age < 10) and (age"
79+
+ " >= 1 and address = '880 Holmes Lane') | fields age, address";
80+
var result = explainQueryToString(query);
81+
String expected = loadFromFile("expectedOutput/calcite/explain_partial_filter_push.json");
82+
assertJsonEqualsIgnoreId(expected, result);
83+
}
84+
85+
// Only for Calcite
86+
@Test
87+
public void supportPartialPushDown_NoPushIfAllFailed() throws IOException {
88+
Assume.assumeTrue("This test is only for push down enabled", isPushdownEnabled());
89+
// field `address` is text type without keyword subfield, so we cannot push it down.
90+
String query =
91+
"source=opensearch-sql_test_index_account | where (address = '671 Bristol Street' or age <"
92+
+ " 10) and (age >= 10 or address = '880 Holmes Lane') | fields age, address";
93+
var result = explainQueryToString(query);
94+
String expected = loadFromFile("expectedOutput/calcite/explain_partial_filter_push2.json");
95+
assertJsonEqualsIgnoreId(expected, result);
96+
}
97+
7198
// Only for Calcite, as v2 gets unstable serialized string for function
7299
@Test
73100
public void testFilterScriptPushDownExplain() throws Exception {

integ-test/src/test/java/org/opensearch/sql/calcite/remote/CalciteRelevanceFunctionIT.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
package org.opensearch.sql.calcite.remote;
77

8+
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_BEER;
9+
10+
import java.io.IOException;
11+
import org.junit.Assume;
812
import org.opensearch.sql.ppl.RelevanceFunctionIT;
913

1014
public class CalciteRelevanceFunctionIT extends RelevanceFunctionIT {
@@ -14,4 +18,17 @@ public void init() throws Exception {
1418
enableCalcite();
1519
disallowCalciteFallback();
1620
}
21+
22+
// For Calcite, this PPL won't throw exception since it supports partial pushdown and has
23+
// optimization rule `FilterProjectTransposeRule` to push down the filter through the project.
24+
@Override
25+
public void not_pushdown_throws_exception() throws IOException {
26+
Assume.assumeTrue("This test is only for push down enabled", isPushdownEnabled());
27+
String query1 =
28+
"SOURCE="
29+
+ TEST_INDEX_BEER
30+
+ " | EVAL answerId = AcceptedAnswerId + 1"
31+
+ " | WHERE simple_query_string(['Tags'], 'taste') and answerId > 200";
32+
assertEquals(5, executeQuery(query1).getInt("total"));
33+
}
1734
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"calcite": {
3+
"logical": "LogicalProject(age=[$8], address=[$2])\n LogicalFilter(condition=[AND(OR(=($7, 'Seattle'), <($8, 10)), >=($8, 1), =($2, '880 Holmes Lane'))])\n CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n",
4+
"physical": "EnumerableCalc(expr#0..1=[{inputs}], expr#2=['880 Holmes Lane':VARCHAR], expr#3=[=($t0, $t2)], age=[$t1], address=[$t0], $condition=[$t3])\n CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]], PushDownContext=[[PROJECT->[address, state, age], FILTER->AND(OR(=($1, 'Seattle'), <($2, 10)), >=($2, 1)), PROJECT->[address, age]], OpenSearchRequestBuilder(sourceBuilder={\"from\":0,\"timeout\":\"1m\",\"query\":{\"bool\":{\"must\":[{\"bool\":{\"should\":[{\"term\":{\"state.keyword\":{\"value\":\"Seattle\",\"boost\":1.0}}},{\"range\":{\"age\":{\"from\":null,\"to\":10,\"include_lower\":true,\"include_upper\":false,\"boost\":1.0}}}],\"adjust_pure_negative\":true,\"boost\":1.0}},{\"range\":{\"age\":{\"from\":1,\"to\":null,\"include_lower\":true,\"include_upper\":true,\"boost\":1.0}}}],\"adjust_pure_negative\":true,\"boost\":1.0}},\"_source\":{\"includes\":[\"address\",\"age\"],\"excludes\":[]},\"sort\":[{\"_doc\":{\"order\":\"asc\"}}]}, requestedTotalSize=2147483647, pageSize=null, startFrom=0)])\n"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"calcite": {
3+
"logical": "LogicalProject(age=[$8], address=[$2])\n LogicalFilter(condition=[AND(OR(=($2, '671 Bristol Street'), <($8, 10)), OR(>=($8, 10), =($2, '880 Holmes Lane')))])\n CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n",
4+
"physical": "EnumerableCalc(expr#0..1=[{inputs}], expr#2=['671 Bristol Street':VARCHAR], expr#3=[=($t0, $t2)], expr#4=[10], expr#5=[<($t1, $t4)], expr#6=[OR($t3, $t5)], expr#7=[>=($t1, $t4)], expr#8=['880 Holmes Lane':VARCHAR], expr#9=[=($t0, $t8)], expr#10=[OR($t7, $t9)], expr#11=[AND($t6, $t10)], age=[$t1], address=[$t0], $condition=[$t11])\n CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]], PushDownContext=[[PROJECT->[address, age]], OpenSearchRequestBuilder(sourceBuilder={\"from\":0,\"timeout\":\"1m\",\"_source\":{\"includes\":[\"address\",\"age\"],\"excludes\":[]}}, requestedTotalSize=2147483647, pageSize=null, startFrom=0)])\n"
5+
}
6+
}

opensearch/src/main/java/org/opensearch/sql/opensearch/planner/physical/OpenSearchFilterIndexScanRule.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.function.Predicate;
88
import org.apache.calcite.plan.RelOptRuleCall;
99
import org.apache.calcite.plan.RelRule;
10+
import org.apache.calcite.rel.AbstractRelNode;
1011
import org.apache.calcite.rel.core.Filter;
1112
import org.apache.calcite.rel.logical.LogicalFilter;
1213
import org.immutables.value.Value;
@@ -37,9 +38,9 @@ public void onMatch(RelOptRuleCall call) {
3738
}
3839

3940
protected void apply(RelOptRuleCall call, Filter filter, CalciteLogicalIndexScan scan) {
40-
CalciteLogicalIndexScan newScan = scan.pushDownFilter(filter);
41-
if (newScan != null) {
42-
call.transformTo(newScan);
41+
AbstractRelNode newRel = scan.pushDownFilter(filter);
42+
if (newRel != null) {
43+
call.transformTo(newRel);
4344
}
4445
}
4546

0 commit comments

Comments
 (0)