Search in sources :

Example 1 with GroupScan

use of org.apache.drill.exec.physical.base.GroupScan in project drill by axbaretto.

the class ParquetPruneScanRule method getFilterOnScanParquet.

public static final RelOptRule getFilterOnScanParquet(OptimizerRulesContext optimizerRulesContext) {
    return new PruneScanRule(RelOptHelper.some(DrillFilterRel.class, RelOptHelper.any(DrillScanRel.class)), "PruneScanRule:Filter_On_Scan_Parquet", optimizerRulesContext) {

        @Override
        public PartitionDescriptor getPartitionDescriptor(PlannerSettings settings, TableScan scanRel) {
            return new ParquetPartitionDescriptor(settings, (DrillScanRel) scanRel);
        }

        @Override
        public boolean matches(RelOptRuleCall call) {
            final DrillScanRel scan = call.rel(1);
            GroupScan groupScan = scan.getGroupScan();
            // this rule is applicable only for parquet based partition pruning
            if (PrelUtil.getPlannerSettings(scan.getCluster().getPlanner()).isHepPartitionPruningEnabled()) {
                return groupScan instanceof ParquetGroupScan && groupScan.supportsPartitionFilterPushdown() && !scan.partitionFilterPushdown();
            } else {
                return groupScan instanceof ParquetGroupScan && groupScan.supportsPartitionFilterPushdown();
            }
        }

        @Override
        public void onMatch(RelOptRuleCall call) {
            final DrillFilterRel filterRel = call.rel(0);
            final DrillScanRel scanRel = call.rel(1);
            doOnMatch(call, filterRel, null, scanRel);
        }
    };
}
Also used : FileGroupScan(org.apache.drill.exec.physical.base.FileGroupScan) GroupScan(org.apache.drill.exec.physical.base.GroupScan) ParquetGroupScan(org.apache.drill.exec.store.parquet.ParquetGroupScan) TableScan(org.apache.calcite.rel.core.TableScan) DrillScanRel(org.apache.drill.exec.planner.logical.DrillScanRel) PlannerSettings(org.apache.drill.exec.planner.physical.PlannerSettings) DrillFilterRel(org.apache.drill.exec.planner.logical.DrillFilterRel) ParquetGroupScan(org.apache.drill.exec.store.parquet.ParquetGroupScan) RelOptRuleCall(org.apache.calcite.plan.RelOptRuleCall) ParquetPartitionDescriptor(org.apache.drill.exec.planner.ParquetPartitionDescriptor)

Example 2 with GroupScan

use of org.apache.drill.exec.physical.base.GroupScan in project drill by apache.

the class HivePushPartitionFilterIntoScan method getFilterOnProject.

public static final StoragePluginOptimizerRule getFilterOnProject(OptimizerRulesContext optimizerRulesContext, final String defaultPartitionValue) {
    return new PruneScanRule(RelOptHelper.some(DrillFilterRel.class, RelOptHelper.some(DrillProjectRel.class, RelOptHelper.any(DrillScanRel.class))), "HivePushPartitionFilterIntoScan:Filter_On_Project_Hive", optimizerRulesContext) {

        @Override
        public PartitionDescriptor getPartitionDescriptor(PlannerSettings settings, TableScan scanRel) {
            return new HivePartitionDescriptor(settings, (DrillScanRel) scanRel, getOptimizerRulesContext().getManagedBuffer(), defaultPartitionValue);
        }

        @Override
        public boolean matches(RelOptRuleCall call) {
            final DrillScanRel scan = (DrillScanRel) call.rel(2);
            GroupScan groupScan = scan.getGroupScan();
            // this rule is applicable only for Hive based partition pruning
            if (PrelUtil.getPlannerSettings(scan.getCluster().getPlanner()).isHepPartitionPruningEnabled()) {
                return groupScan instanceof HiveScan && groupScan.supportsPartitionFilterPushdown() && !scan.partitionFilterPushdown();
            } else {
                return groupScan instanceof HiveScan && groupScan.supportsPartitionFilterPushdown();
            }
        }

        @Override
        public void onMatch(RelOptRuleCall call) {
            final DrillFilterRel filterRel = call.rel(0);
            final DrillProjectRel projectRel = call.rel(1);
            final DrillScanRel scanRel = call.rel(2);
            doOnMatch(call, filterRel, projectRel, scanRel);
        }
    };
}
Also used : GroupScan(org.apache.drill.exec.physical.base.GroupScan) TableScan(org.apache.calcite.rel.core.TableScan) DrillScanRel(org.apache.drill.exec.planner.logical.DrillScanRel) PruneScanRule(org.apache.drill.exec.planner.logical.partition.PruneScanRule) PlannerSettings(org.apache.drill.exec.planner.physical.PlannerSettings) DrillProjectRel(org.apache.drill.exec.planner.logical.DrillProjectRel) HiveScan(org.apache.drill.exec.store.hive.HiveScan) DrillFilterRel(org.apache.drill.exec.planner.logical.DrillFilterRel) RelOptRuleCall(org.apache.calcite.plan.RelOptRuleCall) HivePartitionDescriptor(org.apache.drill.exec.planner.sql.HivePartitionDescriptor)

Example 3 with GroupScan

use of org.apache.drill.exec.physical.base.GroupScan in project drill by apache.

the class HivePushPartitionFilterIntoScan method getFilterOnScan.

public static final StoragePluginOptimizerRule getFilterOnScan(OptimizerRulesContext optimizerRulesContext, final String defaultPartitionValue) {
    return new PruneScanRule(RelOptHelper.some(DrillFilterRel.class, RelOptHelper.any(DrillScanRel.class)), "HivePushPartitionFilterIntoScan:Filter_On_Scan_Hive", optimizerRulesContext) {

        @Override
        public PartitionDescriptor getPartitionDescriptor(PlannerSettings settings, TableScan scanRel) {
            return new HivePartitionDescriptor(settings, (DrillScanRel) scanRel, getOptimizerRulesContext().getManagedBuffer(), defaultPartitionValue);
        }

        @Override
        public boolean matches(RelOptRuleCall call) {
            final DrillScanRel scan = (DrillScanRel) call.rel(1);
            GroupScan groupScan = scan.getGroupScan();
            // this rule is applicable only for Hive based partition pruning
            if (PrelUtil.getPlannerSettings(scan.getCluster().getPlanner()).isHepPartitionPruningEnabled()) {
                return groupScan instanceof HiveScan && groupScan.supportsPartitionFilterPushdown() && !scan.partitionFilterPushdown();
            } else {
                return groupScan instanceof HiveScan && groupScan.supportsPartitionFilterPushdown();
            }
        }

        @Override
        public void onMatch(RelOptRuleCall call) {
            final DrillFilterRel filterRel = call.rel(0);
            final DrillScanRel scanRel = call.rel(1);
            doOnMatch(call, filterRel, null, scanRel);
        }
    };
}
Also used : GroupScan(org.apache.drill.exec.physical.base.GroupScan) TableScan(org.apache.calcite.rel.core.TableScan) DrillScanRel(org.apache.drill.exec.planner.logical.DrillScanRel) PruneScanRule(org.apache.drill.exec.planner.logical.partition.PruneScanRule) PlannerSettings(org.apache.drill.exec.planner.physical.PlannerSettings) HiveScan(org.apache.drill.exec.store.hive.HiveScan) DrillFilterRel(org.apache.drill.exec.planner.logical.DrillFilterRel) RelOptRuleCall(org.apache.calcite.plan.RelOptRuleCall) HivePartitionDescriptor(org.apache.drill.exec.planner.sql.HivePartitionDescriptor)

Example 4 with GroupScan

use of org.apache.drill.exec.physical.base.GroupScan in project drill by apache.

the class DrillRelMdSelectivity method getScanSelectivity.

private Double getScanSelectivity(RelNode rel, RelMetadataQuery mq, RexNode predicate) {
    double ROWCOUNT_UNKNOWN = -1.0;
    GroupScan scan = null;
    PlannerSettings settings = PrelUtil.getPlannerSettings(rel.getCluster().getPlanner());
    final RexBuilder rexBuilder = rel.getCluster().getRexBuilder();
    if (rel instanceof DrillScanRel) {
        scan = ((DrillScanRel) rel).getGroupScan();
    } else if (rel instanceof ScanPrel) {
        scan = ((ScanPrel) rel).getGroupScan();
    }
    if (scan != null) {
        if (settings.isStatisticsEnabled() && scan instanceof DbGroupScan) {
            double filterRows = ((DbGroupScan) scan).getRowCount(predicate, rel);
            double totalRows = ((DbGroupScan) scan).getRowCount(null, rel);
            if (filterRows != ROWCOUNT_UNKNOWN && totalRows != ROWCOUNT_UNKNOWN && totalRows > 0) {
                return Math.min(1.0, filterRows / totalRows);
            }
        }
    }
    // Do not mess with statistics used for DBGroupScans.
    if (rel instanceof TableScan) {
        if (DrillRelOptUtil.guessRows(rel)) {
            return super.getSelectivity(rel, mq, predicate);
        }
        DrillTable table = Utilities.getDrillTable(rel.getTable());
        try {
            TableMetadata tableMetadata;
            if (table != null && (tableMetadata = table.getGroupScan().getTableMetadata()) != null && TableStatisticsKind.HAS_DESCRIPTIVE_STATISTICS.getValue(tableMetadata)) {
                List<SchemaPath> fieldNames;
                if (rel instanceof DrillScanRelBase) {
                    fieldNames = ((DrillScanRelBase) rel).getGroupScan().getColumns();
                } else {
                    fieldNames = rel.getRowType().getFieldNames().stream().map(SchemaPath::getSimplePath).collect(Collectors.toList());
                }
                return getScanSelectivityInternal(tableMetadata, predicate, fieldNames, rexBuilder);
            }
        } catch (IOException e) {
            super.getSelectivity(rel, mq, predicate);
        }
    }
    return super.getSelectivity(rel, mq, predicate);
}
Also used : TableMetadata(org.apache.drill.metastore.metadata.TableMetadata) TableScan(org.apache.calcite.rel.core.TableScan) DrillScanRel(org.apache.drill.exec.planner.logical.DrillScanRel) ScanPrel(org.apache.drill.exec.planner.physical.ScanPrel) DrillTable(org.apache.drill.exec.planner.logical.DrillTable) PlannerSettings(org.apache.drill.exec.planner.physical.PlannerSettings) IOException(java.io.IOException) DbGroupScan(org.apache.drill.exec.physical.base.DbGroupScan) GroupScan(org.apache.drill.exec.physical.base.GroupScan) SchemaPath(org.apache.drill.common.expression.SchemaPath) DbGroupScan(org.apache.drill.exec.physical.base.DbGroupScan) DrillScanRelBase(org.apache.drill.exec.planner.common.DrillScanRelBase) RexBuilder(org.apache.calcite.rex.RexBuilder)

Example 5 with GroupScan

use of org.apache.drill.exec.physical.base.GroupScan in project drill by apache.

the class MongoPluginImplementor method getPhysicalOperator.

@Override
public GroupScan getPhysicalOperator() {
    MongoScanSpec scanSpec = groupScan.getScanSpec();
    List<String> operations = this.operations.stream().map(op -> op.toBsonDocument().toJson()).collect(Collectors.toList());
    String filters = Optional.ofNullable(this.filters).map(Document::toJson).orElse(null);
    MongoScanSpec newSpec = new MongoScanSpec(scanSpec.getDbName(), scanSpec.getCollectionName(), filters, operations);
    return new MongoGroupScan(groupScan.getUserName(), groupScan.getStoragePlugin(), newSpec, columns, runAggregate);
}
Also used : Document(org.bson.Document) Aggregates(com.mongodb.client.model.Aggregates) BsonValue(org.bson.BsonValue) Union(org.apache.calcite.rel.core.Union) Utilities(org.apache.drill.exec.util.Utilities) BigDecimal(java.math.BigDecimal) BsonElement(org.bson.BsonElement) RexNode(org.apache.calcite.rex.RexNode) PluginProjectRel(org.apache.drill.exec.store.plan.rel.PluginProjectRel) PluginLimitRel(org.apache.drill.exec.store.plan.rel.PluginLimitRel) SqlKind(org.apache.calcite.sql.SqlKind) PluginFilterRel(org.apache.drill.exec.store.plan.rel.PluginFilterRel) RexLiteral(org.apache.calcite.rex.RexLiteral) SchemaPath(org.apache.drill.common.expression.SchemaPath) MongoGroupScan(org.apache.drill.exec.store.mongo.MongoGroupScan) LogicalExpression(org.apache.drill.common.expression.LogicalExpression) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) Collectors(java.util.stream.Collectors) List(java.util.List) Sort(org.apache.calcite.rel.core.Sort) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) Optional(java.util.Optional) PluginAggregateRel(org.apache.drill.exec.store.plan.rel.PluginAggregateRel) Project(org.apache.calcite.rel.core.Project) TableScan(org.apache.calcite.rel.core.TableScan) PluginSortRel(org.apache.drill.exec.store.plan.rel.PluginSortRel) Filter(org.apache.calcite.rel.core.Filter) BsonString(org.bson.BsonString) BsonDocument(org.bson.BsonDocument) ArrayList(java.util.ArrayList) AbstractPluginImplementor(org.apache.drill.exec.store.plan.AbstractPluginImplementor) Bson(org.bson.conversions.Bson) DrillOptiq(org.apache.drill.exec.planner.logical.DrillOptiq) MongoAggregateUtils(org.apache.drill.exec.store.mongo.MongoAggregateUtils) Pair(org.apache.calcite.util.Pair) PluginImplementor(org.apache.drill.exec.store.plan.PluginImplementor) JavaTypeFactory(org.apache.calcite.adapter.java.JavaTypeFactory) DrillParseContext(org.apache.drill.exec.planner.logical.DrillParseContext) PrelUtil(org.apache.drill.exec.planner.physical.PrelUtil) PluginUnionRel(org.apache.drill.exec.store.plan.rel.PluginUnionRel) IOException(java.io.IOException) RelNode(org.apache.calcite.rel.RelNode) Aggregate(org.apache.calcite.rel.core.Aggregate) MongoFilterBuilder(org.apache.drill.exec.store.mongo.MongoFilterBuilder) DrillLimitRelBase(org.apache.drill.exec.planner.common.DrillLimitRelBase) GroupScan(org.apache.drill.exec.physical.base.GroupScan) MongoScanSpec(org.apache.drill.exec.store.mongo.MongoScanSpec) AggregateCall(org.apache.calcite.rel.core.AggregateCall) BsonInt32(org.bson.BsonInt32) StoragePluginTableScan(org.apache.drill.exec.store.plan.rel.StoragePluginTableScan) BsonString(org.bson.BsonString) MongoGroupScan(org.apache.drill.exec.store.mongo.MongoGroupScan) MongoScanSpec(org.apache.drill.exec.store.mongo.MongoScanSpec)

Aggregations

GroupScan (org.apache.drill.exec.physical.base.GroupScan)33 DrillScanRel (org.apache.drill.exec.planner.logical.DrillScanRel)19 PlannerSettings (org.apache.drill.exec.planner.physical.PlannerSettings)12 TableScan (org.apache.calcite.rel.core.TableScan)10 RexNode (org.apache.calcite.rex.RexNode)9 RelOptRuleCall (org.apache.calcite.plan.RelOptRuleCall)8 RelNode (org.apache.calcite.rel.RelNode)8 DrillFilterRel (org.apache.drill.exec.planner.logical.DrillFilterRel)8 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)7 SchemaPath (org.apache.drill.common.expression.SchemaPath)6 DrillProjectRel (org.apache.drill.exec.planner.logical.DrillProjectRel)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 DrillParseContext (org.apache.drill.exec.planner.logical.DrillParseContext)5 ScanPrel (org.apache.drill.exec.planner.physical.ScanPrel)5 AggregateCall (org.apache.calcite.rel.core.AggregateCall)4 RelDataType (org.apache.calcite.rel.type.RelDataType)4 DbGroupScan (org.apache.drill.exec.physical.base.DbGroupScan)4 FileGroupScan (org.apache.drill.exec.physical.base.FileGroupScan)4 ParquetPartitionDescriptor (org.apache.drill.exec.planner.ParquetPartitionDescriptor)4