Search in sources :

Example 11 with DrillParseContext

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

the class IndexPlanUtils method buildCollationLowerProject.

/**
 * Build collation property for the 'lower' project, the one closer to the Scan
 * @param projectRexs list of row expressions
 * @param input input as a relational expression
 * @param indexInfo collects functional index information
 * @return the output RelCollation
 */
public static RelCollation buildCollationLowerProject(List<RexNode> projectRexs, RelNode input, FunctionalIndexInfo indexInfo) {
    // if leading fields of index are here, add them to RelCollation
    List<RelFieldCollation> newFields = Lists.newArrayList();
    if (!indexInfo.hasFunctional()) {
        Map<LogicalExpression, Integer> projectExprs = Maps.newLinkedHashMap();
        DrillParseContext parserContext = new DrillParseContext(PrelUtil.getPlannerSettings(input.getCluster()));
        int idx = 0;
        for (RexNode rex : projectRexs) {
            projectExprs.put(DrillOptiq.toDrill(parserContext, input, rex), idx);
            idx++;
        }
        int idxFieldCount = 0;
        for (LogicalExpression expr : indexInfo.getIndexDesc().getIndexColumns()) {
            if (!projectExprs.containsKey(expr)) {
                break;
            }
            RelFieldCollation.Direction dir = indexInfo.getIndexDesc().getCollation().getFieldCollations().get(idxFieldCount).direction;
            if (dir == null) {
                break;
            }
            newFields.add(new RelFieldCollation(projectExprs.get(expr), dir, RelFieldCollation.NullDirection.UNSPECIFIED));
        }
        idxFieldCount++;
    } else {
    // TODO: handle functional index
    }
    return RelCollations.of(newFields);
}
Also used : LogicalExpression(org.apache.drill.common.expression.LogicalExpression) RelFieldCollation(org.apache.calcite.rel.RelFieldCollation) DrillParseContext(org.apache.drill.exec.planner.logical.DrillParseContext) RexNode(org.apache.calcite.rex.RexNode)

Example 12 with DrillParseContext

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

the class NestedLoopJoinPrel method getPhysicalOperator.

@Override
public PhysicalOperator getPhysicalOperator(PhysicalPlanCreator creator) throws IOException {
    PhysicalOperator leftPop = ((Prel) left).getPhysicalOperator(creator);
    PhysicalOperator rightPop = ((Prel) right).getPhysicalOperator(creator);
    /*
       Raw expression will be transformed into its logical representation. For example:
       Query:
         select t1.c1, t2.c1, t2.c2 from t1 inner join t2 on t1.c1 between t2.c1 and t2.c2
       Raw expression:
         AND(>=($0, $1), <=($0, $2))
       Logical expression:
         FunctionCall [func=booleanAnd,
         args=[FunctionCall [func=greater_than_or_equal_to, args=[`i1`, `i10`]],
               FunctionCall [func=less_than_or_equal_to, args=[`i1`, `i2`]]]

       Both tables have the same column name thus duplicated column name in second table are renamed: i1 -> i10.
    */
    LogicalExpression condition = DrillOptiq.toDrill(new DrillParseContext(PrelUtil.getSettings(getCluster())), getInputs(), getCondition());
    NestedLoopJoinPOP nlj = new NestedLoopJoinPOP(leftPop, rightPop, getJoinType(), condition);
    return creator.addMetadata(this, nlj);
}
Also used : LogicalExpression(org.apache.drill.common.expression.LogicalExpression) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) DrillParseContext(org.apache.drill.exec.planner.logical.DrillParseContext) NestedLoopJoinPOP(org.apache.drill.exec.physical.config.NestedLoopJoinPOP)

Example 13 with DrillParseContext

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

the class ParquetPushDownFilter method doOnMatch.

protected void doOnMatch(RelOptRuleCall call, FilterPrel filter, ProjectPrel project, ScanPrel scan) {
    ParquetGroupScan groupScan = (ParquetGroupScan) scan.getGroupScan();
    if (groupScan.getFilter() != null && !groupScan.getFilter().equals(ValueExpressions.BooleanExpression.TRUE)) {
        return;
    }
    RexNode condition = null;
    if (project == null) {
        condition = filter.getCondition();
    } else {
        // get the filter as if it were below the projection.
        condition = RelOptUtil.pushFilterPastProject(filter.getCondition(), project);
    }
    if (condition == null || condition.equals(ValueExpressions.BooleanExpression.TRUE)) {
        return;
    }
    // get a conjunctions of the filter condition. For each conjunction, if it refers to ITEM or FLATTEN expression
    // then we could not pushed down. Otherwise, it's qualified to be pushed down.
    final List<RexNode> predList = RelOptUtil.conjunctions(condition);
    final List<RexNode> qualifiedPredList = Lists.newArrayList();
    for (final RexNode pred : predList) {
        if (DrillRelOptUtil.findItemOrFlatten(pred, ImmutableList.<RexNode>of()) == null) {
            qualifiedPredList.add(pred);
        }
    }
    final RexNode qualifedPred = RexUtil.composeConjunction(filter.getCluster().getRexBuilder(), qualifiedPredList, true);
    if (qualifedPred == null) {
        return;
    }
    LogicalExpression conditionExp = DrillOptiq.toDrill(new DrillParseContext(PrelUtil.getPlannerSettings(call.getPlanner())), scan, qualifedPred);
    Stopwatch timer = Stopwatch.createStarted();
    final GroupScan newGroupScan = groupScan.applyFilter(conditionExp, optimizerContext, optimizerContext.getFunctionRegistry(), optimizerContext.getPlannerSettings().getOptions());
    logger.info("Took {} ms to apply filter on parquet row groups. ", timer.elapsed(TimeUnit.MILLISECONDS));
    if (newGroupScan == null) {
        return;
    }
    final ScanPrel newScanRel = ScanPrel.create(scan, scan.getTraitSet(), newGroupScan, scan.getRowType());
    RelNode inputRel = newScanRel;
    if (project != null) {
        inputRel = project.copy(project.getTraitSet(), ImmutableList.of(inputRel));
    }
    final RelNode newFilter = filter.copy(filter.getTraitSet(), ImmutableList.<RelNode>of(inputRel));
    call.transformTo(newFilter);
}
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) RelNode(org.apache.calcite.rel.RelNode) Stopwatch(com.google.common.base.Stopwatch) DrillParseContext(org.apache.drill.exec.planner.logical.DrillParseContext) RexNode(org.apache.calcite.rex.RexNode)

Example 14 with DrillParseContext

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

the class PruneScanRule method materializePruneExpr.

protected LogicalExpression materializePruneExpr(RexNode pruneCondition, PlannerSettings settings, RelNode scanRel, VectorContainer container) {
    // materialize the expression
    logger.debug("Attempting to prune {}", pruneCondition);
    final LogicalExpression expr = DrillOptiq.toDrill(new DrillParseContext(settings), scanRel, pruneCondition);
    final ErrorCollectorImpl errors = new ErrorCollectorImpl();
    LogicalExpression materializedExpr = ExpressionTreeMaterializer.materialize(expr, container, errors, optimizerContext.getFunctionRegistry());
    // it's same as the type of output vector.
    if (materializedExpr.getMajorType().getMode() == TypeProtos.DataMode.REQUIRED) {
        materializedExpr = ExpressionTreeMaterializer.convertToNullableType(materializedExpr, materializedExpr.getMajorType().getMinorType(), optimizerContext.getFunctionRegistry(), errors);
    }
    if (errors.getErrorCount() != 0) {
        logger.warn("Failure while materializing expression [{}].  Errors: {}", expr, errors);
        return null;
    }
    return materializedExpr;
}
Also used : ErrorCollectorImpl(org.apache.drill.common.expression.ErrorCollectorImpl) LogicalExpression(org.apache.drill.common.expression.LogicalExpression) DrillParseContext(org.apache.drill.exec.planner.logical.DrillParseContext)

Example 15 with DrillParseContext

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

the class NestedLoopJoinPrel method getPhysicalOperator.

@Override
public PhysicalOperator getPhysicalOperator(PhysicalPlanCreator creator) throws IOException {
    PhysicalOperator leftPop = ((Prel) left).getPhysicalOperator(creator);
    PhysicalOperator rightPop = ((Prel) right).getPhysicalOperator(creator);
    /*
       Raw expression will be transformed into its logical representation. For example:
       Query:
         select t1.c1, t2.c1, t2.c2 from t1 inner join t2 on t1.c1 between t2.c1 and t2.c2
       Raw expression:
         AND(>=($0, $1), <=($0, $2))
       Logical expression:
         FunctionCall [func=booleanAnd,
         args=[FunctionCall [func=greater_than_or_equal_to, args=[`i1`, `i10`]],
               FunctionCall [func=less_than_or_equal_to, args=[`i1`, `i2`]]]

       Both tables have the same column name thus duplicated column name in second table are renamed: i1 -> i10.
    */
    LogicalExpression condition = DrillOptiq.toDrill(new DrillParseContext(PrelUtil.getSettings(getCluster())), getInputs(), getCondition());
    NestedLoopJoinPOP nlj = new NestedLoopJoinPOP(leftPop, rightPop, getJoinType(), condition);
    return creator.addMetadata(this, nlj);
}
Also used : LogicalExpression(org.apache.drill.common.expression.LogicalExpression) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) DrillParseContext(org.apache.drill.exec.planner.logical.DrillParseContext) NestedLoopJoinPOP(org.apache.drill.exec.physical.config.NestedLoopJoinPOP)

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