Search in sources :

Example 1 with ProjectPushInfo

use of org.apache.drill.exec.planner.common.DrillRelOptUtil.ProjectPushInfo in project drill by apache.

the class DrillPushProjectIntoScanRule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    Project project = call.rel(0);
    TableScan scan = call.rel(1);
    try {
        if (scan.getRowType().getFieldList().isEmpty()) {
            return;
        }
        ProjectPushInfo projectPushInfo = DrillRelOptUtil.getFieldsInformation(scan.getRowType(), project.getProjects());
        if (!canPushProjectIntoScan(scan.getTable(), projectPushInfo) || skipScanConversion(projectPushInfo.createNewRowType(project.getCluster().getTypeFactory()), scan)) {
            // project above scan may be removed in ProjectRemoveRule for the case when it is trivial
            return;
        }
        TableScan newScan = createScan(scan, projectPushInfo);
        List<RexNode> newProjects = new ArrayList<>();
        for (RexNode n : project.getChildExps()) {
            newProjects.add(n.accept(projectPushInfo.getInputReWriter()));
        }
        Project newProject = createProject(project, newScan, newProjects);
        if (ProjectRemoveRule.isTrivial(newProject)) {
            call.transformTo(newScan);
        } else {
            call.transformTo(newProject);
        }
    } catch (IOException e) {
        throw new DrillRuntimeException(e);
    }
}
Also used : Project(org.apache.calcite.rel.core.Project) LogicalProject(org.apache.calcite.rel.logical.LogicalProject) TableScan(org.apache.calcite.rel.core.TableScan) EnumerableTableScan(org.apache.calcite.adapter.enumerable.EnumerableTableScan) ProjectPushInfo(org.apache.drill.exec.planner.common.DrillRelOptUtil.ProjectPushInfo) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 EnumerableTableScan (org.apache.calcite.adapter.enumerable.EnumerableTableScan)1 Project (org.apache.calcite.rel.core.Project)1 TableScan (org.apache.calcite.rel.core.TableScan)1 LogicalProject (org.apache.calcite.rel.logical.LogicalProject)1 RexNode (org.apache.calcite.rex.RexNode)1 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)1 ProjectPushInfo (org.apache.drill.exec.planner.common.DrillRelOptUtil.ProjectPushInfo)1