Skip to content

Commit b0b7df5

Browse files
committed
Test explaining partial pushdown filter with isnull
Signed-off-by: Yuanchun Shen <yuanchu@amazon.com>
1 parent a20f006 commit b0b7df5

4 files changed

Lines changed: 31 additions & 0 deletions

File tree

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

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

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

8+
import static org.opensearch.sql.legacy.TestsConstants.TEST_INDEX_NESTED_SIMPLE;
89
import static org.opensearch.sql.util.MatcherUtils.assertJsonEqualsIgnoreId;
910

1011
import java.io.IOException;
12+
import java.util.Locale;
1113
import org.junit.Assume;
1214
import org.junit.Ignore;
1315
import org.junit.Test;
@@ -18,6 +20,7 @@ public class CalciteExplainIT extends ExplainIT {
1820
public void init() throws Exception {
1921
super.init();
2022
enableCalcite();
23+
loadIndex(Index.NESTED_SIMPLE);
2124
}
2225

2326
@Override
@@ -108,6 +111,20 @@ public void supportPartialPushDownScript() throws IOException {
108111
assertJsonEqualsIgnoreId(expected, result);
109112
}
110113

114+
@Test
115+
public void testPartialPushdownFilterWithIsNull() throws IOException {
116+
// isnull(nested_field) should not be pushed down since DSL doesn't handle it correctly, but
117+
// name='david' can be pushed down
118+
String query =
119+
String.format(
120+
Locale.ROOT,
121+
"source=%s | where isnull(address) and name='david'",
122+
TEST_INDEX_NESTED_SIMPLE);
123+
var result = explainQueryToString(query);
124+
String expected = loadExpectedPlan("explain_partial_filter_isnull.json");
125+
assertJsonEqualsIgnoreId(expected, result);
126+
}
127+
111128
@Test
112129
public void testSkipScriptEncodingOnExtendedFormat() throws IOException {
113130
Assume.assumeTrue("This test is only for push down enabled", isPushdownEnabled());
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"calcite": {
3+
"logical": "LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT])\n LogicalProject(name=[$0], address=[$1], id=[$6], age=[$7])\n LogicalFilter(condition=[AND(IS NULL($1), =($0, 'david'))])\n CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_nested_simple]])\n",
4+
"physical": "EnumerableLimit(fetch=[10000])\n EnumerableCalc(expr#0..3=[{inputs}], expr#4=[IS NULL($t1)], proj#0..3=[{exprs}], $condition=[$t4])\n CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_nested_simple]], PushDownContext=[[PROJECT->[name, address, id, age], FILTER->=($0, 'david')], OpenSearchRequestBuilder(sourceBuilder={\"from\":0,\"timeout\":\"1m\",\"query\":{\"bool\":{\"must\":[{\"term\":{\"name.keyword\":{\"value\":\"david\",\"boost\":1.0}}}],\"adjust_pure_negative\":true,\"boost\":1.0}},\"_source\":{\"includes\":[\"name\",\"address\",\"id\",\"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": "LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT])\n LogicalProject(name=[$0], address=[$1], id=[$6], age=[$7])\n LogicalFilter(condition=[AND(IS NULL($1), =($0, 'david'))])\n CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_nested_simple]])\n",
4+
"physical": "EnumerableLimit(fetch=[10000])\n EnumerableCalc(expr#0..13=[{inputs}], expr#14=[IS NULL($t1)], expr#15=['david':VARCHAR], expr#16=[=($t0, $t15)], expr#17=[AND($t14, $t16)], proj#0..1=[{exprs}], id=[$t6], age=[$t7], $condition=[$t17])\n CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_nested_simple]])\n"
5+
}
6+
}

opensearch/src/main/java/org/opensearch/sql/opensearch/request/PredicateAnalyzer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,8 @@ public ScriptQueryExpression(
13621362
RelDataType rowType,
13631363
Map<String, ExprType> fieldTypes,
13641364
RelOptCluster cluster) {
1365+
// We prevent is_null(nested_field) from being pushed down because pushed-down scripts can not
1366+
// access nested fields for the time being
13651367
if (rexNode instanceof RexCall
13661368
&& (rexNode.getKind().equals(SqlKind.IS_NULL)
13671369
|| rexNode.getKind().equals(SqlKind.IS_NOT_NULL))) {

0 commit comments

Comments
 (0)