Skip to content

Commit de8803d

Browse files
committed
Various fixes
1 parent 7abb95f commit de8803d

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillRelFactories.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import org.apache.calcite.rel.core.RelFactories;
2828
import org.apache.calcite.rel.hint.RelHint;
2929
import org.apache.calcite.rel.type.RelDataType;
30+
import org.apache.calcite.rex.RexInputRef;
3031
import org.apache.calcite.rex.RexNode;
32+
import org.apache.calcite.rex.RexShuttle;
3133
import org.apache.calcite.rex.RexUtil;
3234
import org.apache.calcite.sql.SqlKind;
3335
import org.apache.calcite.tools.RelBuilderFactory;
@@ -136,7 +138,25 @@ public RelNode createProject(RelNode input, List<RelHint> hints, List<? extends
136138
private static class DrillFilterFactoryImpl implements RelFactories.FilterFactory {
137139
@Override
138140
public RelNode createFilter(RelNode child, RexNode condition, Set<CorrelationId> variablesSet) {
139-
return DrillFilterRel.create(child, condition);
141+
// Normalize nullability of RexInputRef nodes to match the input's row type
142+
// This is necessary for Calcite 1.37+ which has stricter type checking
143+
RexNode normalizedCondition = condition.accept(new RexShuttle() {
144+
@Override
145+
public RexNode visitInputRef(RexInputRef inputRef) {
146+
int index = inputRef.getIndex();
147+
if (index >= child.getRowType().getFieldCount()) {
148+
return inputRef;
149+
}
150+
RelDataType actualType = child.getRowType().getFieldList().get(index).getType();
151+
// If nullability differs, create a new RexInputRef with correct nullability
152+
if (inputRef.getType().isNullable() != actualType.isNullable() ||
153+
!inputRef.getType().equals(actualType)) {
154+
return new RexInputRef(index, actualType);
155+
}
156+
return inputRef;
157+
}
158+
});
159+
return DrillFilterRel.create(child, normalizedCondition);
140160
}
141161
}
142162

exec/java-exec/src/test/java/org/apache/drill/TestPartitionFilter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,10 @@ public void testPartitionFilterWithLike() throws Exception {
423423
public void testPartitionFilterWithInSubquery() throws Exception {
424424
String query = "select * from dfs.`multilevel/parquet` where cast (dir0 as int) IN (1994, 1994, 1994, 1994, 1994, 1994)";
425425
try {
426-
/* In list size exceeds threshold - no partition pruning since predicate converted to join */
426+
/* In list size exceeds threshold - partition pruning still works in Calcite 1.37+
427+
* due to JoinPushTransitivePredicatesRule pushing predicates through semi-joins */
427428
client.alterSession(PlannerSettings.IN_SUBQUERY_THRESHOLD.getOptionName(), 2);
428-
testExcludeFilter(query, 12, "Filter\\(", 40);
429+
testExcludeFilter(query, 4, "Filter\\(", 40);
429430
/* In list size does not exceed threshold - partition pruning */
430431
client.alterSession(PlannerSettings.IN_SUBQUERY_THRESHOLD.getOptionName(), 10);
431432
testExcludeFilter(query, 4, "Filter\\(", 40);

0 commit comments

Comments
 (0)