Search in sources :

Example 1 with TableScan

use of org.apache.calcite.rel.core.TableScan in project storm by apache.

the class PlanCompiler method doChainOperators.

private void doChainOperators(PrintWriter pw, RelNode node, Set<TableScan> tables, String parentCtx) {
    pw.print(String.format("    ChannelContext CTX_%d = Channels.chain(%2$s, %3$s);\n", node.getId(), parentCtx, RelNodeCompiler.getStageName(node)));
    String currentCtx = String.format("CTX_%d", node.getId());
    if (node instanceof TableScan) {
        tables.add((TableScan) node);
    }
    for (RelNode i : node.getInputs()) {
        doChainOperators(pw, i, tables, currentCtx);
    }
}
Also used : TableScan(org.apache.calcite.rel.core.TableScan) RelNode(org.apache.calcite.rel.RelNode)

Example 2 with TableScan

use of org.apache.calcite.rel.core.TableScan in project drill by apache.

the class DrillPushProjIntoScan method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    final Project proj = (Project) call.rel(0);
    final TableScan scan = (TableScan) call.rel(1);
    try {
        ProjectPushInfo columnInfo = PrelUtil.getColumns(scan.getRowType(), proj.getProjects());
        // get DrillTable, either wrapped in RelOptTable, or DrillTranslatableTable.
        DrillTable table = scan.getTable().unwrap(DrillTable.class);
        if (table == null) {
            table = scan.getTable().unwrap(DrillTranslatableTable.class).getDrillTable();
        }
        if (//
        columnInfo == null || columnInfo.isStarQuery() || !//
        table.getGroupScan().canPushdownProjects(columnInfo.columns)) {
            return;
        }
        final DrillScanRel newScan = new DrillScanRel(scan.getCluster(), scan.getTraitSet().plus(DrillRel.DRILL_LOGICAL), scan.getTable(), columnInfo.createNewRowType(proj.getInput().getCluster().getTypeFactory()), columnInfo.columns);
        List<RexNode> newProjects = Lists.newArrayList();
        for (RexNode n : proj.getChildExps()) {
            newProjects.add(n.accept(columnInfo.getInputRewriter()));
        }
        final DrillProjectRel newProj = new DrillProjectRel(proj.getCluster(), proj.getTraitSet().plus(DrillRel.DRILL_LOGICAL), newScan, newProjects, proj.getRowType());
        if (ProjectRemoveRule.isTrivial(newProj)) {
            call.transformTo(newScan);
        } else {
            call.transformTo(newProj);
        }
    } catch (IOException e) {
        throw new DrillRuntimeException(e);
    }
}
Also used : Project(org.apache.calcite.rel.core.Project) LogicalProject(org.apache.calcite.rel.logical.LogicalProject) TableScan(org.apache.calcite.rel.core.TableScan) EnumerableTableScan(org.apache.calcite.adapter.enumerable.EnumerableTableScan) ProjectPushInfo(org.apache.drill.exec.planner.physical.PrelUtil.ProjectPushInfo) IOException(java.io.IOException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) RexNode(org.apache.calcite.rex.RexNode)

Example 3 with TableScan

use of org.apache.calcite.rel.core.TableScan in project calcite by apache.

the class DruidQuery method isValid.

@Override
public boolean isValid(Litmus litmus, Context context) {
    if (!super.isValid(litmus, context)) {
        return false;
    }
    final String signature = signature();
    if (!isValidSignature(signature)) {
        return litmus.fail("invalid signature [{}]", signature);
    }
    if (rels.isEmpty()) {
        return litmus.fail("must have at least one rel");
    }
    for (int i = 0; i < rels.size(); i++) {
        final RelNode r = rels.get(i);
        if (i == 0) {
            if (!(r instanceof TableScan)) {
                return litmus.fail("first rel must be TableScan, was ", r);
            }
            if (r.getTable() != table) {
                return litmus.fail("first rel must be based on table table");
            }
        } else {
            final List<RelNode> inputs = r.getInputs();
            if (inputs.size() != 1 || inputs.get(0) != rels.get(i - 1)) {
                return litmus.fail("each rel must have a single input");
            }
            if (r instanceof Aggregate) {
                final Aggregate aggregate = (Aggregate) r;
                if (aggregate.getGroupSets().size() != 1 || aggregate.indicator) {
                    return litmus.fail("no grouping sets");
                }
            }
            if (r instanceof Filter) {
                final Filter filter = (Filter) r;
                final DruidJsonFilter druidJsonFilter = DruidJsonFilter.toDruidFilters(filter.getCondition(), filter.getInput().getRowType(), this);
                if (druidJsonFilter == null) {
                    return litmus.fail("invalid filter [{}]", filter.getCondition());
                }
            }
            if (r instanceof Sort) {
                final Sort sort = (Sort) r;
                if (sort.offset != null && RexLiteral.intValue(sort.offset) != 0) {
                    return litmus.fail("offset not supported");
                }
            }
        }
    }
    return true;
}
Also used : TableScan(org.apache.calcite.rel.core.TableScan) AbstractRelNode(org.apache.calcite.rel.AbstractRelNode) RelNode(org.apache.calcite.rel.RelNode) Filter(org.apache.calcite.rel.core.Filter) Sort(org.apache.calcite.rel.core.Sort) Aggregate(org.apache.calcite.rel.core.Aggregate)

Example 4 with TableScan

use of org.apache.calcite.rel.core.TableScan in project calcite by apache.

the class DruidTable method toRel.

public RelNode toRel(RelOptTable.ToRelContext context, RelOptTable relOptTable) {
    final RelOptCluster cluster = context.getCluster();
    final TableScan scan = LogicalTableScan.create(cluster, relOptTable);
    return DruidQuery.create(cluster, cluster.traitSetOf(BindableConvention.INSTANCE), relOptTable, this, ImmutableList.<RelNode>of(scan));
}
Also used : RelOptCluster(org.apache.calcite.plan.RelOptCluster) TableScan(org.apache.calcite.rel.core.TableScan) LogicalTableScan(org.apache.calcite.rel.logical.LogicalTableScan)

Example 5 with TableScan

use of org.apache.calcite.rel.core.TableScan in project drill by axbaretto.

the class DrillPushProjectIntoScanRule method onMatch.

@Override
public void onMatch(RelOptRuleCall call) {
    final Project project = call.rel(0);
    final TableScan scan = call.rel(1);
    try {
        if (scan.getRowType().getFieldList().isEmpty()) {
            return;
        }
        ProjectPushInfo projectPushInfo = getFieldsInformation(scan.getRowType(), project.getProjects());
        if (!canPushProjectIntoScan(scan.getTable(), projectPushInfo)) {
            return;
        }
        final DrillScanRel newScan = new DrillScanRel(scan.getCluster(), scan.getTraitSet().plus(DrillRel.DRILL_LOGICAL), scan.getTable(), projectPushInfo.createNewRowType(project.getInput().getCluster().getTypeFactory()), projectPushInfo.getFields());
        List<RexNode> newProjects = new ArrayList<>();
        for (RexNode n : project.getChildExps()) {
            newProjects.add(n.accept(projectPushInfo.getInputReWriter()));
        }
        final DrillProjectRel newProject = new DrillProjectRel(project.getCluster(), project.getTraitSet().plus(DrillRel.DRILL_LOGICAL), newScan, newProjects, project.getRowType());
        if (ProjectRemoveRule.isTrivial(newProject)) {
            call.transformTo(newScan);
        } else {
            call.transformTo(newProject);
        }
    } catch (IOException e) {
        throw new DrillRuntimeException(e);
    }
}
Also used : Project(org.apache.calcite.rel.core.Project) LogicalProject(org.apache.calcite.rel.logical.LogicalProject) TableScan(org.apache.calcite.rel.core.TableScan) EnumerableTableScan(org.apache.calcite.adapter.enumerable.EnumerableTableScan) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

TableScan (org.apache.calcite.rel.core.TableScan)51 RelNode (org.apache.calcite.rel.RelNode)19 ArrayList (java.util.ArrayList)13 PlannerSettings (org.apache.drill.exec.planner.physical.PlannerSettings)13 Project (org.apache.calcite.rel.core.Project)12 DrillScanRel (org.apache.drill.exec.planner.logical.DrillScanRel)11 Filter (org.apache.calcite.rel.core.Filter)10 IOException (java.io.IOException)9 RexNode (org.apache.calcite.rex.RexNode)9 GroupScan (org.apache.drill.exec.physical.base.GroupScan)9 RelOptRuleCall (org.apache.calcite.plan.RelOptRuleCall)8 DrillFilterRel (org.apache.drill.exec.planner.logical.DrillFilterRel)8 Aggregate (org.apache.calcite.rel.core.Aggregate)7 LogicalProject (org.apache.calcite.rel.logical.LogicalProject)7 RexBuilder (org.apache.calcite.rex.RexBuilder)6 RelOptCluster (org.apache.calcite.plan.RelOptCluster)5 RelShuttleImpl (org.apache.calcite.rel.RelShuttleImpl)5 LogicalJoin (org.apache.calcite.rel.logical.LogicalJoin)5 RelDataType (org.apache.calcite.rel.type.RelDataType)5 SchemaPath (org.apache.drill.common.expression.SchemaPath)5