Search in sources :

Example 31 with DrillParseContext

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

the class WindowPrel method toDrill.

protected LogicalExpression toDrill(AggregateCall call, List<String> fn) {
    DrillParseContext context = new DrillParseContext(PrelUtil.getSettings(getCluster()));
    List<LogicalExpression> args = Lists.newArrayList();
    for (Integer i : call.getArgList()) {
        final int indexInConstants = i - fn.size();
        if (i < fn.size()) {
            args.add(new FieldReference(fn.get(i)));
        } else {
            final RexLiteral constant = constants.get(indexInConstants);
            LogicalExpression expr = DrillOptiq.toDrill(context, getInput(), constant);
            args.add(expr);
        }
    }
    // for count(1).
    if (args.isEmpty()) {
        args.add(new ValueExpressions.LongExpression(1l));
    }
    return new FunctionCall(call.getAggregation().getName().toLowerCase(), args, ExpressionPosition.UNKNOWN);
}
Also used : LogicalExpression(org.apache.drill.common.expression.LogicalExpression) RexLiteral(org.apache.calcite.rex.RexLiteral) FieldReference(org.apache.drill.common.expression.FieldReference) ValueExpressions(org.apache.drill.common.expression.ValueExpressions) DrillParseContext(org.apache.drill.exec.planner.logical.DrillParseContext) FunctionCall(org.apache.drill.common.expression.FunctionCall)

Example 32 with DrillParseContext

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

the class ProjectPrel method getPhysicalOperator.

@Override
public PhysicalOperator getPhysicalOperator(PhysicalPlanCreator creator) throws IOException {
    Prel child = (Prel) this.getInput();
    PhysicalOperator childPOP = child.getPhysicalOperator(creator);
    org.apache.drill.exec.physical.config.Project p = new org.apache.drill.exec.physical.config.Project(this.getProjectExpressions(new DrillParseContext(PrelUtil.getSettings(getCluster()))), childPOP, outputProj);
    return creator.addMetadata(this, p);
}
Also used : Project(org.apache.calcite.rel.core.Project) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) DrillParseContext(org.apache.drill.exec.planner.logical.DrillParseContext)

Example 33 with DrillParseContext

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

the class ProjectAllowDupPrel method getPhysicalOperator.

@Override
public PhysicalOperator getPhysicalOperator(PhysicalPlanCreator creator) throws IOException {
    Prel child = (Prel) this.getInput();
    PhysicalOperator childPOP = child.getPhysicalOperator(creator);
    Project p = new Project(this.getProjectExpressions(new DrillParseContext(PrelUtil.getSettings(getCluster()))), childPOP, outputProj);
    return creator.addMetadata(this, p);
}
Also used : Project(org.apache.drill.exec.physical.config.Project) PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) DrillParseContext(org.apache.drill.exec.planner.logical.DrillParseContext)

Example 34 with DrillParseContext

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

the class IcebergPluginImplementor method implement.

@Override
public void implement(PluginProjectRel project) throws IOException {
    visitChild(project.getInput());
    DrillParseContext context = new DrillParseContext(PrelUtil.getPlannerSettings(project.getCluster().getPlanner()));
    RelNode input = project.getInput();
    List<SchemaPath> projects = project.getProjects().stream().map(e -> (SchemaPath) DrillOptiq.toDrill(context, input, e)).collect(Collectors.toList());
    groupScan = groupScan.clone(projects);
}
Also used : Project(org.apache.calcite.rel.core.Project) IcebergGroupScan(org.apache.drill.exec.store.iceberg.IcebergGroupScan) RelShuttleImpl(org.apache.calcite.rel.RelShuttleImpl) Filter(org.apache.calcite.rel.core.Filter) RelSubset(org.apache.calcite.plan.volcano.RelSubset) AbstractPluginImplementor(org.apache.drill.exec.store.plan.AbstractPluginImplementor) BigDecimal(java.math.BigDecimal) DrillOptiq(org.apache.drill.exec.planner.logical.DrillOptiq) Expression(org.apache.iceberg.expressions.Expression) RexNode(org.apache.calcite.rex.RexNode) PluginProjectRel(org.apache.drill.exec.store.plan.rel.PluginProjectRel) DrillParseContext(org.apache.drill.exec.planner.logical.DrillParseContext) PrelUtil(org.apache.drill.exec.planner.physical.PrelUtil) PluginLimitRel(org.apache.drill.exec.store.plan.rel.PluginLimitRel) PluginFilterRel(org.apache.drill.exec.store.plan.rel.PluginFilterRel) Binder(org.apache.iceberg.expressions.Binder) RexLiteral(org.apache.calcite.rex.RexLiteral) SchemaPath(org.apache.drill.common.expression.SchemaPath) IOException(java.io.IOException) RelNode(org.apache.calcite.rel.RelNode) LogicalExpression(org.apache.drill.common.expression.LogicalExpression) Collectors(java.util.stream.Collectors) ValidationException(org.apache.iceberg.exceptions.ValidationException) List(java.util.List) DrillLimitRelBase(org.apache.drill.exec.planner.common.DrillLimitRelBase) GroupScan(org.apache.drill.exec.physical.base.GroupScan) Util(org.apache.calcite.util.Util) StoragePluginTableScan(org.apache.drill.exec.store.plan.rel.StoragePluginTableScan) RelNode(org.apache.calcite.rel.RelNode) SchemaPath(org.apache.drill.common.expression.SchemaPath) DrillParseContext(org.apache.drill.exec.planner.logical.DrillParseContext)

Example 35 with DrillParseContext

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

the class IcebergPluginImplementor method canImplement.

@Override
public boolean canImplement(Filter filter) {
    RexNode condition = filter.getCondition();
    LogicalExpression logicalExpression = DrillOptiq.toDrill(new DrillParseContext(PrelUtil.getPlannerSettings(filter.getCluster().getPlanner())), filter.getInput(), condition);
    Expression expression = logicalExpression.accept(DrillExprToIcebergTranslator.INSTANCE, null);
    if (expression != null) {
        try {
            GroupScan scan = findGroupScan(filter);
            if (scan instanceof IcebergGroupScan) {
                IcebergGroupScan groupScan = (IcebergGroupScan) scan;
                // ensures that expression compatible with table schema
                expression = Binder.bind(groupScan.getTableScan().schema().asStruct(), expression, true);
            } else {
                return false;
            }
        } catch (ValidationException e) {
            return false;
        }
    }
    return expression != null;
}
Also used : IcebergGroupScan(org.apache.drill.exec.store.iceberg.IcebergGroupScan) GroupScan(org.apache.drill.exec.physical.base.GroupScan) LogicalExpression(org.apache.drill.common.expression.LogicalExpression) ValidationException(org.apache.iceberg.exceptions.ValidationException) Expression(org.apache.iceberg.expressions.Expression) LogicalExpression(org.apache.drill.common.expression.LogicalExpression) DrillParseContext(org.apache.drill.exec.planner.logical.DrillParseContext) IcebergGroupScan(org.apache.drill.exec.store.iceberg.IcebergGroupScan) RexNode(org.apache.calcite.rex.RexNode)

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