Search in sources :

Example 1 with JsonTableGroupScan

use of org.apache.drill.exec.store.mapr.db.json.JsonTableGroupScan in project drill by apache.

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 2 with JsonTableGroupScan

use of org.apache.drill.exec.store.mapr.db.json.JsonTableGroupScan in project drill by apache.

the class MapRDBFormatPlugin method getGroupScan.

@Override
public AbstractGroupScan getGroupScan(String userName, FileSelection selection, List<SchemaPath> columns) throws IOException {
    List<String> files = selection.getFiles();
    assert (files.size() == 1);
    String tableName = files.get(0);
    TableProperties props = getMaprFS().getTableProperties(new Path(tableName));
    if (props.getAttr().getJson()) {
        JsonScanSpec scanSpec = new JsonScanSpec(tableName, null);
        return new JsonTableGroupScan(userName, getStoragePlugin(), this, scanSpec, columns);
    } else {
        HBaseScanSpec scanSpec = new HBaseScanSpec(tableName);
        return new BinaryTableGroupScan(userName, getStoragePlugin(), this, scanSpec, columns);
    }
}
Also used : SchemaPath(org.apache.drill.common.expression.SchemaPath) Path(org.apache.hadoop.fs.Path) HBaseScanSpec(org.apache.drill.exec.store.hbase.HBaseScanSpec) JsonTableGroupScan(org.apache.drill.exec.store.mapr.db.json.JsonTableGroupScan) JsonScanSpec(org.apache.drill.exec.store.mapr.db.json.JsonScanSpec) TableProperties(com.mapr.fs.tables.TableProperties) BinaryTableGroupScan(org.apache.drill.exec.store.mapr.db.binary.BinaryTableGroupScan)

Aggregations

JsonScanSpec (org.apache.drill.exec.store.mapr.db.json.JsonScanSpec)2 JsonTableGroupScan (org.apache.drill.exec.store.mapr.db.json.JsonTableGroupScan)2 TableProperties (com.mapr.fs.tables.TableProperties)1 RelNode (org.apache.calcite.rel.RelNode)1 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)1 SchemaPath (org.apache.drill.common.expression.SchemaPath)1 DrillParseContext (org.apache.drill.exec.planner.logical.DrillParseContext)1 ScanPrel (org.apache.drill.exec.planner.physical.ScanPrel)1 HBaseScanSpec (org.apache.drill.exec.store.hbase.HBaseScanSpec)1 BinaryTableGroupScan (org.apache.drill.exec.store.mapr.db.binary.BinaryTableGroupScan)1 JsonConditionBuilder (org.apache.drill.exec.store.mapr.db.json.JsonConditionBuilder)1 Path (org.apache.hadoop.fs.Path)1