|  | 
|  | 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 | +} | 
0 commit comments