Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,16 @@ public void supportSearchSargPushDown_timeRange() throws IOException {
+ "| where birthdate >= '2016-12-08 00:00:00.000000000' "
+ "and birthdate < '2018-11-09 00:00:00.000000000' "));
}

// Only for Calcite
@Test
public void supportPartialPushDown() throws IOException {
// field `address` is text type without keyword subfield, so we cannot push it down.
String query =
"source=opensearch-sql_test_index_account | where age >= 1 and address = '880 Holmes Lane'"
+ " | fields age, address";
var result = explainQueryToString(query);
String expected = loadFromFile("expectedOutput/calcite/explain_partial_filter_push.json");
assertJsonEqualsIgnoreId(expected, result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"calcite": {
"logical": "LogicalProject(age=[$8], address=[$2])\n LogicalFilter(condition=[AND(>=($8, 1), =($2, '880 Holmes Lane'))])\n CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_account]])\n",
"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, age], FILTER->AND(>=($1, 1), =($0, '880 Holmes Lane'))], OpenSearchRequestBuilder(sourceBuilder={\"from\":0,\"timeout\":\"1m\",\"query\":{\"bool\":{\"must\":[{\"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"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't be FILTER->[>=($1, 1)] instead of FILTER->AND(>=($1, 1), =($0, '880 Holmes Lane')) in PushDownContext?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It uses the original condition currently as its digest now. If we needs to use the pushed condition as its digest, we need to store that RexNode as well like non-pushed condition. Both is ok for functionality, the latter one should be more appropriate for explanation.

Will make that change.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.function.Predicate;
import org.apache.calcite.plan.RelOptRuleCall;
import org.apache.calcite.plan.RelRule;
import org.apache.calcite.rel.AbstractRelNode;
import org.apache.calcite.rel.core.Filter;
import org.apache.calcite.rel.logical.LogicalFilter;
import org.immutables.value.Value;
Expand Down Expand Up @@ -37,9 +38,9 @@ public void onMatch(RelOptRuleCall call) {
}

protected void apply(RelOptRuleCall call, Filter filter, CalciteLogicalIndexScan scan) {
CalciteLogicalIndexScan newScan = scan.pushDownFilter(filter);
if (newScan != null) {
call.transformTo(newScan);
AbstractRelNode newRel = scan.pushDownFilter(filter);
if (newRel != null) {
call.transformTo(newRel);
}
}

Expand Down
Loading
Loading