Skip to content

Commit b1599a1

Browse files
committed
Fix Unit Tests
1 parent 7abb95f commit b1599a1

File tree

3 files changed

+78
-7
lines changed

3 files changed

+78
-7
lines changed

exec/java-exec/src/main/java/org/apache/drill/exec/planner/RuleInstance.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.apache.calcite.rel.rules.FilterSetOpTransposeRule;
3030
import org.apache.calcite.rel.rules.JoinPushExpressionsRule;
3131
import org.apache.calcite.rel.rules.JoinPushThroughJoinRule;
32-
import org.apache.calcite.rel.rules.JoinPushTransitivePredicatesRule;
32+
import org.apache.drill.exec.planner.logical.DrillJoinPushTransitivePredicatesRule;
3333
import org.apache.calcite.rel.rules.ProjectRemoveRule;
3434
import org.apache.calcite.rel.rules.ProjectSetOpTransposeRule;
3535
import org.apache.calcite.rel.rules.ProjectToWindowRule;
@@ -171,12 +171,9 @@ public boolean matches(RelOptRuleCall call) {
171171
* {@link org.apache.calcite.rel.core.Join} and creates
172172
* {@link org.apache.calcite.rel.core.Filter}s if those predicates can be pushed
173173
* to its inputs.
174+
* Uses Drill-specific version that excludes SEMI joins to preserve partition pruning behavior.
174175
*/
175-
RelOptRule DRILL_JOIN_PUSH_TRANSITIVE_PREDICATES_RULE =
176-
JoinPushTransitivePredicatesRule.Config.DEFAULT
177-
.withRelBuilderFactory(DrillRelBuilder.proto(
178-
DrillRelFactories.DRILL_LOGICAL_JOIN_FACTORY, DrillRelFactories.DRILL_LOGICAL_FILTER_FACTORY))
179-
.toRule();
176+
RelOptRule DRILL_JOIN_PUSH_TRANSITIVE_PREDICATES_RULE = DrillJoinPushTransitivePredicatesRule.INSTANCE;
180177

181178
RelOptRule REMOVE_IS_NOT_DISTINCT_FROM_RULE =
182179
FilterRemoveIsNotDistinctFromRule.Config.DEFAULT
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.drill.exec.planner.logical;
19+
20+
import org.apache.calcite.plan.RelOptRuleCall;
21+
import org.apache.calcite.rel.core.Join;
22+
import org.apache.calcite.rel.core.JoinRelType;
23+
import org.apache.calcite.rel.rules.JoinPushTransitivePredicatesRule;
24+
import org.apache.drill.exec.planner.DrillRelBuilder;
25+
26+
/**
27+
* Drill-specific version of JoinPushTransitivePredicatesRule that excludes SEMI joins.
28+
* SEMI joins are used for IN clause conversion and pushing predicates through them
29+
* can interfere with partition pruning logic.
30+
*/
31+
public class DrillJoinPushTransitivePredicatesRule extends JoinPushTransitivePredicatesRule {
32+
33+
protected DrillJoinPushTransitivePredicatesRule(Config config) {
34+
super(config);
35+
}
36+
37+
@Override
38+
public boolean matches(RelOptRuleCall call) {
39+
Join join = call.rel(0);
40+
// Don't apply this rule to SEMI joins to preserve partition pruning behavior
41+
if (join.getJoinType() == JoinRelType.SEMI) {
42+
return false;
43+
}
44+
return super.matches(call);
45+
}
46+
47+
public static final DrillJoinPushTransitivePredicatesRule INSTANCE =
48+
new DrillJoinPushTransitivePredicatesRule(
49+
JoinPushTransitivePredicatesRule.Config.DEFAULT
50+
.withRelBuilderFactory(DrillRelBuilder.proto(
51+
DrillRelFactories.DRILL_LOGICAL_JOIN_FACTORY,
52+
DrillRelFactories.DRILL_LOGICAL_FILTER_FACTORY))
53+
.as(JoinPushTransitivePredicatesRule.Config.class));
54+
}

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

0 commit comments

Comments
 (0)