Github user chunhui-shi commented on a diff in the pull request:

    https://github.com/apache/drill/pull/1104#discussion_r166088073
  
    --- Diff: 
exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillFilterItemStarReWriterRule.java
 ---
    @@ -0,0 +1,232 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + * http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.drill.exec.planner.logical;
    +
    +import com.google.common.collect.ImmutableList;
    +import com.google.common.collect.ImmutableSet;
    +import org.apache.calcite.adapter.enumerable.EnumerableTableScan;
    +import org.apache.calcite.plan.RelOptRule;
    +import org.apache.calcite.plan.RelOptRuleCall;
    +import org.apache.calcite.plan.RelOptRuleOperand;
    +import org.apache.calcite.plan.RelOptTable;
    +import org.apache.calcite.prepare.RelOptTableImpl;
    +import org.apache.calcite.rel.RelNode;
    +import org.apache.calcite.rel.core.CorrelationId;
    +import org.apache.calcite.rel.core.Filter;
    +import org.apache.calcite.rel.core.Project;
    +import org.apache.calcite.rel.core.TableScan;
    +import org.apache.calcite.rel.logical.LogicalFilter;
    +import org.apache.calcite.rel.logical.LogicalProject;
    +import org.apache.calcite.rel.type.RelDataType;
    +import org.apache.calcite.rel.type.RelDataTypeFactory;
    +import org.apache.calcite.rel.type.RelDataTypeField;
    +import org.apache.calcite.rex.RexCall;
    +import org.apache.calcite.rex.RexInputRef;
    +import org.apache.calcite.rex.RexNode;
    +import org.apache.calcite.rex.RexVisitorImpl;
    +import org.apache.calcite.schema.Table;
    +import org.apache.drill.exec.planner.types.RelDataTypeDrillImpl;
    +import org.apache.drill.exec.planner.types.RelDataTypeHolder;
    +import org.apache.drill.exec.util.Utilities;
    +
    +import java.util.ArrayList;
    +import java.util.Collection;
    +import java.util.HashMap;
    +import java.util.List;
    +import java.util.Map;
    +
    +import static 
org.apache.drill.exec.planner.logical.FieldsReWriterUtil.DesiredField;
    +import static 
org.apache.drill.exec.planner.logical.FieldsReWriterUtil.FieldsReWriter;
    +
    +/**
    + * Rule will transform filter -> project -> scan call with item star 
fields in filter
    + * into project -> filter -> project -> scan where item star fields are 
pushed into scan
    + * and replaced with actual field references.
    + *
    + * This will help partition pruning and push down rules to detect fields 
that can be pruned or push downed.
    + * Item star operator appears when sub-select or cte with star are used as 
source.
    + */
    +public class DrillFilterItemStarReWriterRule extends RelOptRule {
    +
    +  public static final DrillFilterItemStarReWriterRule INSTANCE = new 
DrillFilterItemStarReWriterRule(
    +      RelOptHelper.some(Filter.class, RelOptHelper.some(Project.class, 
RelOptHelper.any( TableScan.class))),
    +      "DrillFilterItemStarReWriterRule");
    +
    +  private DrillFilterItemStarReWriterRule(RelOptRuleOperand operand, 
String id) {
    +    super(operand, id);
    +  }
    +
    +  @Override
    +  public void onMatch(RelOptRuleCall call) {
    +    Filter filterRel = call.rel(0);
    +    Project projectRel = call.rel(1);
    +    TableScan scanRel = call.rel(2);
    +
    +    ItemStarFieldsVisitor itemStarFieldsVisitor = new 
ItemStarFieldsVisitor(filterRel.getRowType().getFieldNames());
    --- End diff --
    
    To make sure this works for complex expressions, could you add tests 
similar to testPushProjectIntoScan to test some expressions that include more 
than two fields in expressions in project(e.g. "select a+b") and in filter(e.g. 
"where a+b < 5")?  


---

Reply via email to