Search in sources :

Example 1 with RewriteAsBinaryOperators

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

the class DbScanToIndexScanPrule method doOnMatch.

protected void doOnMatch(IndexLogicalPlanCallContext indexContext) {
    Stopwatch indexPlanTimer = Stopwatch.createStarted();
    final PlannerSettings settings = PrelUtil.getPlannerSettings(indexContext.call.getPlanner());
    final IndexCollection indexCollection = getIndexCollection(settings, indexContext.scan);
    if (indexCollection == null) {
        return;
    }
    logger.debug("Index Rule {} starts", this.description);
    RexBuilder builder = indexContext.filter.getCluster().getRexBuilder();
    RexNode condition = null;
    if (indexContext.lowerProject == null) {
        condition = indexContext.filter.getCondition();
    } else {
        // get the filter as if it were below the projection.
        condition = RelOptUtil.pushFilterPastProject(indexContext.filter.getCondition(), indexContext.lowerProject);
    }
    // save this pushed down condition, in case it is needed later to build filter when joining back primary table
    indexContext.origPushedCondition = condition;
    RewriteAsBinaryOperators visitor = new RewriteAsBinaryOperators(true, builder);
    condition = condition.accept(visitor);
    if (indexCollection.supportsIndexSelection()) {
        try {
            processWithIndexSelection(indexContext, settings, condition, indexCollection, builder);
        } catch (Exception e) {
            logger.warn("Exception while doing index planning ", e);
        }
    } else {
        throw new UnsupportedOperationException("Index collection must support index selection");
    }
    indexPlanTimer.stop();
    logger.info("index_plan_info: Index Planning took {} ms", indexPlanTimer.elapsed(TimeUnit.MILLISECONDS));
}
Also used : PlannerSettings(org.apache.drill.exec.planner.physical.PlannerSettings) RewriteAsBinaryOperators(org.apache.drill.exec.planner.logical.partition.RewriteAsBinaryOperators) Stopwatch(org.apache.drill.shaded.guava.com.google.common.base.Stopwatch) RexBuilder(org.apache.calcite.rex.RexBuilder) IndexCollection(org.apache.drill.exec.planner.index.IndexCollection) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

RexBuilder (org.apache.calcite.rex.RexBuilder)1 RexNode (org.apache.calcite.rex.RexNode)1 IndexCollection (org.apache.drill.exec.planner.index.IndexCollection)1 RewriteAsBinaryOperators (org.apache.drill.exec.planner.logical.partition.RewriteAsBinaryOperators)1 PlannerSettings (org.apache.drill.exec.planner.physical.PlannerSettings)1 Stopwatch (org.apache.drill.shaded.guava.com.google.common.base.Stopwatch)1