Search in sources :

Example 6 with FilterPrel

use of org.apache.drill.exec.planner.physical.FilterPrel in project drill by axbaretto.

the class ParquetPushDownFilter method getFilterOnScan.

public static StoragePluginOptimizerRule getFilterOnScan(OptimizerRulesContext optimizerContext) {
    return new ParquetPushDownFilter(RelOptHelper.some(FilterPrel.class, RelOptHelper.any(ScanPrel.class)), "ParquetPushDownFilter:Filter_On_Scan", optimizerContext) {

        @Override
        public boolean matches(RelOptRuleCall call) {
            final ScanPrel scan = call.rel(1);
            if (scan.getGroupScan() instanceof ParquetGroupScan) {
                return super.matches(call);
            }
            return false;
        }

        @Override
        public void onMatch(RelOptRuleCall call) {
            final FilterPrel filterRel = call.rel(0);
            final ScanPrel scanRel = call.rel(1);
            doOnMatch(call, filterRel, null, scanRel);
        }
    };
}
Also used : ScanPrel(org.apache.drill.exec.planner.physical.ScanPrel) RelOptRuleCall(org.apache.calcite.plan.RelOptRuleCall) FilterPrel(org.apache.drill.exec.planner.physical.FilterPrel)

Example 7 with FilterPrel

use of org.apache.drill.exec.planner.physical.FilterPrel in project drill by apache.

the class ParquetPushDownFilter method getFilterOnScan.

public static StoragePluginOptimizerRule getFilterOnScan(OptimizerRulesContext optimizerContext) {
    return new ParquetPushDownFilter(RelOptHelper.some(FilterPrel.class, RelOptHelper.any(ScanPrel.class)), "ParquetPushDownFilter:Filter_On_Scan", optimizerContext) {

        @Override
        public boolean matches(RelOptRuleCall call) {
            final ScanPrel scan = call.rel(1);
            if (scan.getGroupScan() instanceof ParquetGroupScan) {
                return super.matches(call);
            }
            return false;
        }

        @Override
        public void onMatch(RelOptRuleCall call) {
            final FilterPrel filterRel = call.rel(0);
            final ScanPrel scanRel = call.rel(1);
            doOnMatch(call, filterRel, null, scanRel);
        }
    };
}
Also used : ScanPrel(org.apache.drill.exec.planner.physical.ScanPrel) RelOptRuleCall(org.apache.calcite.plan.RelOptRuleCall) FilterPrel(org.apache.drill.exec.planner.physical.FilterPrel)

Example 8 with FilterPrel

use of org.apache.drill.exec.planner.physical.FilterPrel in project drill by axbaretto.

the class MongoPushDownFilterForScan method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    final ScanPrel scan = (ScanPrel) call.rel(1);
    final FilterPrel filter = (FilterPrel) call.rel(0);
    final RexNode condition = filter.getCondition();
    MongoGroupScan groupScan = (MongoGroupScan) scan.getGroupScan();
    if (groupScan.isFilterPushedDown()) {
        return;
    }
    LogicalExpression conditionExp = DrillOptiq.toDrill(new DrillParseContext(PrelUtil.getPlannerSettings(call.getPlanner())), scan, condition);
    MongoFilterBuilder mongoFilterBuilder = new MongoFilterBuilder(groupScan, conditionExp);
    MongoScanSpec newScanSpec = mongoFilterBuilder.parseTree();
    if (newScanSpec == null) {
        // no filter pushdown so nothing to apply.
        return;
    }
    MongoGroupScan newGroupsScan = null;
    try {
        newGroupsScan = new MongoGroupScan(groupScan.getUserName(), groupScan.getStoragePlugin(), newScanSpec, groupScan.getColumns());
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        throw new DrillRuntimeException(e.getMessage(), e);
    }
    newGroupsScan.setFilterPushedDown(true);
    final ScanPrel newScanPrel = ScanPrel.create(scan, filter.getTraitSet(), newGroupsScan, scan.getRowType());
    if (mongoFilterBuilder.isAllExpressionsConverted()) {
        /*
       * Since we could convert the entire filter condition expression into an
       * Mongo filter, we can eliminate the filter operator altogether.
       */
        call.transformTo(newScanPrel);
    } else {
        call.transformTo(filter.copy(filter.getTraitSet(), ImmutableList.of((RelNode) newScanPrel)));
    }
}
Also used : LogicalExpression(org.apache.drill.common.expression.LogicalExpression) ScanPrel(org.apache.drill.exec.planner.physical.ScanPrel) DrillParseContext(org.apache.drill.exec.planner.logical.DrillParseContext) IOException(java.io.IOException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) FilterPrel(org.apache.drill.exec.planner.physical.FilterPrel) RexNode(org.apache.calcite.rex.RexNode)

Example 9 with FilterPrel

use of org.apache.drill.exec.planner.physical.FilterPrel in project drill by axbaretto.

the class ParquetPushDownFilter method getFilterOnProject.

public static RelOptRule getFilterOnProject(OptimizerRulesContext optimizerRulesContext) {
    return new ParquetPushDownFilter(RelOptHelper.some(FilterPrel.class, RelOptHelper.some(ProjectPrel.class, RelOptHelper.any(ScanPrel.class))), "ParquetPushDownFilter:Filter_On_Project", optimizerRulesContext) {

        @Override
        public boolean matches(RelOptRuleCall call) {
            final ScanPrel scan = call.rel(2);
            if (scan.getGroupScan() instanceof ParquetGroupScan) {
                return super.matches(call);
            }
            return false;
        }

        @Override
        public void onMatch(RelOptRuleCall call) {
            final FilterPrel filterRel = call.rel(0);
            final ProjectPrel projectRel = call.rel(1);
            final ScanPrel scanRel = call.rel(2);
            doOnMatch(call, filterRel, projectRel, scanRel);
        }
    };
}
Also used : ProjectPrel(org.apache.drill.exec.planner.physical.ProjectPrel) ScanPrel(org.apache.drill.exec.planner.physical.ScanPrel) RelOptRuleCall(org.apache.calcite.plan.RelOptRuleCall) FilterPrel(org.apache.drill.exec.planner.physical.FilterPrel)

Example 10 with FilterPrel

use of org.apache.drill.exec.planner.physical.FilterPrel in project drill by apache.

the class DruidPushDownFilterForScan method onMatch.

@Override
public void onMatch(RelOptRuleCall relOptRuleCall) {
    final ScanPrel scan = relOptRuleCall.rel(1);
    final FilterPrel filter = relOptRuleCall.rel(0);
    final RexNode condition = filter.getCondition();
    DruidGroupScan groupScan = (DruidGroupScan) scan.getGroupScan();
    if (groupScan.isFilterPushedDown()) {
        return;
    }
    LogicalExpression conditionExp = DrillOptiq.toDrill(new DrillParseContext(PrelUtil.getPlannerSettings(relOptRuleCall.getPlanner())), scan, condition);
    DruidFilterBuilder druidFilterBuilder = new DruidFilterBuilder(groupScan, conditionExp);
    DruidScanSpec newScanSpec = druidFilterBuilder.parseTree();
    if (newScanSpec == null) {
        // no filter pushdown so nothing to apply.
        return;
    }
    DruidGroupScan newGroupsScan = new DruidGroupScan(groupScan.getUserName(), groupScan.getStoragePlugin(), newScanSpec, groupScan.getColumns(), groupScan.getMaxRecordsToRead());
    newGroupsScan.setFilterPushedDown(true);
    ScanPrel newScanPrel = scan.copy(filter.getTraitSet(), newGroupsScan, filter.getRowType());
    if (druidFilterBuilder.isAllExpressionsConverted()) {
        /*
       * Since we could convert the entire filter condition expression into a
       * Druid filter, we can eliminate the filter operator altogether.
       */
        relOptRuleCall.transformTo(newScanPrel);
    } else {
        relOptRuleCall.transformTo(filter.copy(filter.getTraitSet(), ImmutableList.of(newScanPrel)));
    }
}
Also used : LogicalExpression(org.apache.drill.common.expression.LogicalExpression) ScanPrel(org.apache.drill.exec.planner.physical.ScanPrel) DrillParseContext(org.apache.drill.exec.planner.logical.DrillParseContext) FilterPrel(org.apache.drill.exec.planner.physical.FilterPrel) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

FilterPrel (org.apache.drill.exec.planner.physical.FilterPrel)14 ScanPrel (org.apache.drill.exec.planner.physical.ScanPrel)14 RexNode (org.apache.calcite.rex.RexNode)8 ProjectPrel (org.apache.drill.exec.planner.physical.ProjectPrel)7 RelOptRuleCall (org.apache.calcite.plan.RelOptRuleCall)6 DrillParseContext (org.apache.drill.exec.planner.logical.DrillParseContext)5 RelTraitSet (org.apache.calcite.plan.RelTraitSet)4 RelNode (org.apache.calcite.rel.RelNode)4 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)4 RelDataType (org.apache.calcite.rel.type.RelDataType)3 RelDataTypeFactory (org.apache.calcite.rel.type.RelDataTypeFactory)3 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)3 DrillDistributionTrait (org.apache.drill.exec.planner.physical.DrillDistributionTrait)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 RelCollation (org.apache.calcite.rel.RelCollation)2 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)2 SchemaPath (org.apache.drill.common.expression.SchemaPath)2 DbGroupScan (org.apache.drill.exec.physical.base.DbGroupScan)2 IndexGroupScan (org.apache.drill.exec.physical.base.IndexGroupScan)2