Search in sources :

Example 21 with DrillParseContext

use of org.apache.drill.exec.planner.logical.DrillParseContext in project drill by axbaretto.

the class InfoSchemaPushFilterIntoRecordGenerator method doMatch.

protected void doMatch(RelOptRuleCall call, ScanPrel scan, ProjectPrel project, FilterPrel filter) {
    final RexNode condition = filter.getCondition();
    InfoSchemaGroupScan groupScan = (InfoSchemaGroupScan) scan.getGroupScan();
    if (groupScan.isFilterPushedDown()) {
        return;
    }
    LogicalExpression conditionExp = DrillOptiq.toDrill(new DrillParseContext(PrelUtil.getPlannerSettings(call.getPlanner())), project != null ? project : scan, condition);
    InfoSchemaFilterBuilder filterBuilder = new InfoSchemaFilterBuilder(conditionExp);
    InfoSchemaFilter infoSchemaFilter = filterBuilder.build();
    if (infoSchemaFilter == null) {
        // no filter pushdown ==> No transformation.
        return;
    }
    final InfoSchemaGroupScan newGroupsScan = new InfoSchemaGroupScan(groupScan.getTable(), infoSchemaFilter);
    newGroupsScan.setFilterPushedDown(true);
    RelNode input = ScanPrel.create(scan, filter.getTraitSet(), newGroupsScan, scan.getRowType());
    if (project != null) {
        input = project.copy(project.getTraitSet(), input, project.getProjects(), filter.getRowType());
    }
    if (filterBuilder.isAllExpressionsConverted()) {
        // Filter can be removed as all expressions in the filter are converted and pushed to scan
        call.transformTo(input);
    } else {
        call.transformTo(filter.copy(filter.getTraitSet(), ImmutableList.of(input)));
    }
}
Also used : LogicalExpression(org.apache.drill.common.expression.LogicalExpression) RelNode(org.apache.calcite.rel.RelNode) DrillParseContext(org.apache.drill.exec.planner.logical.DrillParseContext) RexNode(org.apache.calcite.rex.RexNode)

Example 22 with DrillParseContext

use of org.apache.drill.exec.planner.logical.DrillParseContext in project drill by axbaretto.

the class MapRDBPushFilterIntoScan method doPushFilterIntoBinaryGroupScan.

protected void doPushFilterIntoBinaryGroupScan(final RelOptRuleCall call, final FilterPrel filter, final ProjectPrel project, final ScanPrel scan, final BinaryTableGroupScan groupScan, final RexNode condition) {
    if (groupScan.isFilterPushedDown()) {
        /*
       * The rule can get triggered again due to the transformed "scan => filter" sequence
       * created by the earlier execution of this rule when we could not do a complete
       * conversion of Optiq Filter's condition to HBase Filter. In such cases, we rely upon
       * this flag to not do a re-processing of the rule on the already transformed call.
       */
        return;
    }
    final LogicalExpression conditionExp = DrillOptiq.toDrill(new DrillParseContext(PrelUtil.getPlannerSettings(call.getPlanner())), scan, condition);
    final MapRDBFilterBuilder maprdbFilterBuilder = new MapRDBFilterBuilder(groupScan, conditionExp);
    final HBaseScanSpec newScanSpec = maprdbFilterBuilder.parseTree();
    if (newScanSpec == null) {
        // no filter pushdown ==> No transformation.
        return;
    }
    // Pass tableStats from old groupScan so we do not go and fetch stats (an expensive operation) again from MapR DB client.
    final BinaryTableGroupScan newGroupsScan = new BinaryTableGroupScan(groupScan.getUserName(), groupScan.getStoragePlugin(), groupScan.getFormatPlugin(), newScanSpec, groupScan.getColumns(), groupScan.getTableStats());
    newGroupsScan.setFilterPushedDown(true);
    final ScanPrel newScanPrel = ScanPrel.create(scan, filter.getTraitSet(), newGroupsScan, scan.getRowType());
    // Depending on whether is a project in the middle, assign either scan or copy of project to childRel.
    final RelNode childRel = project == null ? newScanPrel : project.copy(project.getTraitSet(), ImmutableList.of((RelNode) newScanPrel));
    ;
    if (maprdbFilterBuilder.isAllExpressionsConverted()) {
        /*
         * Since we could convert the entire filter condition expression into an HBase filter,
         * we can eliminate the filter operator altogether.
         */
        call.transformTo(childRel);
    } else {
        call.transformTo(filter.copy(filter.getTraitSet(), ImmutableList.of(childRel)));
    }
}
Also used : HBaseScanSpec(org.apache.drill.exec.store.hbase.HBaseScanSpec) LogicalExpression(org.apache.drill.common.expression.LogicalExpression) ScanPrel(org.apache.drill.exec.planner.physical.ScanPrel) MapRDBFilterBuilder(org.apache.drill.exec.store.mapr.db.binary.MapRDBFilterBuilder) RelNode(org.apache.calcite.rel.RelNode) DrillParseContext(org.apache.drill.exec.planner.logical.DrillParseContext) BinaryTableGroupScan(org.apache.drill.exec.store.mapr.db.binary.BinaryTableGroupScan)

Example 23 with DrillParseContext

use of org.apache.drill.exec.planner.logical.DrillParseContext in project drill by axbaretto.

the class MapRDBPushFilterIntoScan method doPushFilterIntoJsonGroupScan.

protected void doPushFilterIntoJsonGroupScan(RelOptRuleCall call, FilterPrel filter, final ProjectPrel project, ScanPrel scan, JsonTableGroupScan groupScan, RexNode condition) {
    if (// Do not pushdown filter if it is disabled in plugin configuration
    groupScan.isDisablePushdown() || groupScan.isFilterPushedDown()) {
        /*
       * The rule can get triggered again due to the transformed "scan => filter" sequence
       * created by the earlier execution of this rule when we could not do a complete
       * conversion of Optiq Filter's condition to HBase Filter. In such cases, we rely upon
       * this flag to not do a re-processing of the rule on the already transformed call.
       */
        return;
    }
    LogicalExpression conditionExp = null;
    try {
        conditionExp = DrillOptiq.toDrill(new DrillParseContext(PrelUtil.getPlannerSettings(call.getPlanner())), scan, condition);
    } catch (ClassCastException e) {
        // For such cases, we return without pushdown
        return;
    }
    final JsonConditionBuilder jsonConditionBuilder = new JsonConditionBuilder(groupScan, conditionExp);
    final JsonScanSpec newScanSpec = jsonConditionBuilder.parseTree();
    if (newScanSpec == null) {
        // no filter pushdown ==> No transformation.
        return;
    }
    // clone the groupScan with the newScanSpec.
    final JsonTableGroupScan newGroupsScan = groupScan.clone(newScanSpec);
    newGroupsScan.setFilterPushedDown(true);
    final ScanPrel newScanPrel = ScanPrel.create(scan, filter.getTraitSet(), newGroupsScan, scan.getRowType());
    // Depending on whether is a project in the middle, assign either scan or copy of project to childRel.
    final RelNode childRel = project == null ? newScanPrel : project.copy(project.getTraitSet(), ImmutableList.of((RelNode) newScanPrel));
    ;
    if (jsonConditionBuilder.isAllExpressionsConverted()) {
        /*
         * Since we could convert the entire filter condition expression into an HBase filter,
         * we can eliminate the filter operator altogether.
         */
        call.transformTo(childRel);
    } else {
        call.transformTo(filter.copy(filter.getTraitSet(), ImmutableList.of(childRel)));
    }
}
Also used : LogicalExpression(org.apache.drill.common.expression.LogicalExpression) ScanPrel(org.apache.drill.exec.planner.physical.ScanPrel) RelNode(org.apache.calcite.rel.RelNode) DrillParseContext(org.apache.drill.exec.planner.logical.DrillParseContext) JsonTableGroupScan(org.apache.drill.exec.store.mapr.db.json.JsonTableGroupScan) JsonConditionBuilder(org.apache.drill.exec.store.mapr.db.json.JsonConditionBuilder) JsonScanSpec(org.apache.drill.exec.store.mapr.db.json.JsonScanSpec)

Example 24 with DrillParseContext

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

Example 25 with DrillParseContext

use of org.apache.drill.exec.planner.logical.DrillParseContext in project drill by apache.

the class KafkaPushDownFilterIntoScan method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    final ScanPrel scan = call.rel(1);
    final FilterPrel filter = call.rel(0);
    final RexNode condition = filter.getCondition();
    LogicalExpression conditionExp = DrillOptiq.toDrill(new DrillParseContext(PrelUtil.getPlannerSettings(call.getPlanner())), scan, condition);
    KafkaGroupScan groupScan = (KafkaGroupScan) scan.getGroupScan();
    if (logger.isDebugEnabled()) {
        logger.debug("Partitions ScanSpec before push down: {}", groupScan.getPartitionScanSpecList());
    }
    List<KafkaPartitionScanSpec> newScanSpec;
    try (KafkaPartitionScanSpecBuilder builder = new KafkaPartitionScanSpecBuilder(groupScan, conditionExp)) {
        newScanSpec = builder.parseTree();
    }
    // No pushdown
    if (newScanSpec == null) {
        return;
    }
    logger.debug("Partitions ScanSpec after pushdown: {}", newScanSpec);
    GroupScan newGroupScan = groupScan.cloneWithNewSpec(newScanSpec);
    final ScanPrel newScanPrel = new ScanPrel(scan.getCluster(), filter.getTraitSet(), newGroupScan, scan.getRowType(), scan.getTable());
    call.transformTo(filter.copy(filter.getTraitSet(), ImmutableList.of(newScanPrel)));
}
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) DrillParseContext(org.apache.drill.exec.planner.logical.DrillParseContext) FilterPrel(org.apache.drill.exec.planner.physical.FilterPrel) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

DrillParseContext (org.apache.drill.exec.planner.logical.DrillParseContext)41 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)31 RexNode (org.apache.calcite.rex.RexNode)17 ScanPrel (org.apache.drill.exec.planner.physical.ScanPrel)16 RelNode (org.apache.calcite.rel.RelNode)14 PhysicalOperator (org.apache.drill.exec.physical.base.PhysicalOperator)10 GroupScan (org.apache.drill.exec.physical.base.GroupScan)5 FilterPrel (org.apache.drill.exec.planner.physical.FilterPrel)5 IOException (java.io.IOException)3 RelTraitSet (org.apache.calcite.plan.RelTraitSet)3 RelFieldCollation (org.apache.calcite.rel.RelFieldCollation)3 Project (org.apache.calcite.rel.core.Project)3 RexLiteral (org.apache.calcite.rex.RexLiteral)3 SchemaPath (org.apache.drill.common.expression.SchemaPath)3 ProjectPrel (org.apache.drill.exec.planner.physical.ProjectPrel)3 Stopwatch (com.google.common.base.Stopwatch)2 RelCollation (org.apache.calcite.rel.RelCollation)2 Filter (org.apache.calcite.rel.core.Filter)2 RelDataTypeField (org.apache.calcite.rel.type.RelDataTypeField)2 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)2