Search in sources :

Example 6 with ScanPrel

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

the class ParquetPushDownFilter method doOnMatch.

protected void doOnMatch(RelOptRuleCall call, FilterPrel filter, ProjectPrel project, ScanPrel scan) {
    ParquetGroupScan groupScan = (ParquetGroupScan) scan.getGroupScan();
    if (groupScan.getFilter() != null && !groupScan.getFilter().equals(ValueExpressions.BooleanExpression.TRUE)) {
        return;
    }
    RexNode condition = null;
    if (project == null) {
        condition = filter.getCondition();
    } else {
        // get the filter as if it were below the projection.
        condition = RelOptUtil.pushFilterPastProject(filter.getCondition(), project);
    }
    if (condition == null || condition.equals(ValueExpressions.BooleanExpression.TRUE)) {
        return;
    }
    // get a conjunctions of the filter condition. For each conjunction, if it refers to ITEM or FLATTEN expression
    // then we could not pushed down. Otherwise, it's qualified to be pushed down.
    final List<RexNode> predList = RelOptUtil.conjunctions(condition);
    final List<RexNode> qualifiedPredList = Lists.newArrayList();
    for (final RexNode pred : predList) {
        if (DrillRelOptUtil.findItemOrFlatten(pred, ImmutableList.<RexNode>of()) == null) {
            qualifiedPredList.add(pred);
        }
    }
    final RexNode qualifedPred = RexUtil.composeConjunction(filter.getCluster().getRexBuilder(), qualifiedPredList, true);
    if (qualifedPred == null) {
        return;
    }
    LogicalExpression conditionExp = DrillOptiq.toDrill(new DrillParseContext(PrelUtil.getPlannerSettings(call.getPlanner())), scan, qualifedPred);
    Stopwatch timer = Stopwatch.createStarted();
    final GroupScan newGroupScan = groupScan.applyFilter(conditionExp, optimizerContext, optimizerContext.getFunctionRegistry(), optimizerContext.getPlannerSettings().getOptions());
    logger.info("Took {} ms to apply filter on parquet row groups. ", timer.elapsed(TimeUnit.MILLISECONDS));
    if (newGroupScan == null) {
        return;
    }
    final ScanPrel newScanRel = ScanPrel.create(scan, scan.getTraitSet(), newGroupScan, scan.getRowType());
    RelNode inputRel = newScanRel;
    if (project != null) {
        inputRel = project.copy(project.getTraitSet(), ImmutableList.of(inputRel));
    }
    final RelNode newFilter = filter.copy(filter.getTraitSet(), ImmutableList.<RelNode>of(inputRel));
    call.transformTo(newFilter);
}
Also used : GroupScan(org.apache.drill.exec.physical.base.GroupScan) LogicalExpression(org.apache.drill.common.expression.LogicalExpression) ScanPrel(org.apache.drill.exec.planner.physical.ScanPrel) RelNode(org.apache.calcite.rel.RelNode) Stopwatch(com.google.common.base.Stopwatch) DrillParseContext(org.apache.drill.exec.planner.logical.DrillParseContext) RexNode(org.apache.calcite.rex.RexNode)

Example 7 with ScanPrel

use of org.apache.drill.exec.planner.physical.ScanPrel 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)

Aggregations

ScanPrel (org.apache.drill.exec.planner.physical.ScanPrel)7 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)5 DrillParseContext (org.apache.drill.exec.planner.logical.DrillParseContext)5 RelNode (org.apache.calcite.rel.RelNode)4 FilterPrel (org.apache.drill.exec.planner.physical.FilterPrel)3 RelOptRuleCall (org.apache.calcite.plan.RelOptRuleCall)2 RexNode (org.apache.calcite.rex.RexNode)2 Stopwatch (com.google.common.base.Stopwatch)1 IOException (java.io.IOException)1 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)1 GroupScan (org.apache.drill.exec.physical.base.GroupScan)1 ProjectPrel (org.apache.drill.exec.planner.physical.ProjectPrel)1 HBaseScanSpec (org.apache.drill.exec.store.hbase.HBaseScanSpec)1 BinaryTableGroupScan (org.apache.drill.exec.store.mapr.db.binary.BinaryTableGroupScan)1 MapRDBFilterBuilder (org.apache.drill.exec.store.mapr.db.binary.MapRDBFilterBuilder)1 JsonConditionBuilder (org.apache.drill.exec.store.mapr.db.json.JsonConditionBuilder)1 JsonScanSpec (org.apache.drill.exec.store.mapr.db.json.JsonScanSpec)1 JsonTableGroupScan (org.apache.drill.exec.store.mapr.db.json.JsonTableGroupScan)1