Search in sources :

Example 1 with MapRDBFilterBuilder

use of org.apache.drill.exec.store.mapr.db.binary.MapRDBFilterBuilder in project drill by apache.

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(), groupScan.getMetadataProvider());
    newGroupsScan.setFilterPushedDown(true);
    final ScanPrel newScanPrel = new ScanPrel(scan.getCluster(), filter.getTraitSet(), newGroupsScan, scan.getRowType(), scan.getTable());
    // 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 2 with MapRDBFilterBuilder

use of org.apache.drill.exec.store.mapr.db.binary.MapRDBFilterBuilder 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)

Aggregations

RelNode (org.apache.calcite.rel.RelNode)2 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)2 DrillParseContext (org.apache.drill.exec.planner.logical.DrillParseContext)2 ScanPrel (org.apache.drill.exec.planner.physical.ScanPrel)2 HBaseScanSpec (org.apache.drill.exec.store.hbase.HBaseScanSpec)2 BinaryTableGroupScan (org.apache.drill.exec.store.mapr.db.binary.BinaryTableGroupScan)2 MapRDBFilterBuilder (org.apache.drill.exec.store.mapr.db.binary.MapRDBFilterBuilder)2