Search in sources :

Example 6 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 7 with TableScan

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

the class TridentScanRule method convert.

@Override
public RelNode convert(RelNode rel) {
    final TableScan scan = (TableScan) rel;
    int parallelismHint = DEFAULT_PARALLELISM_HINT;
    final ParallelStreamableTable parallelTable = scan.getTable().unwrap(ParallelStreamableTable.class);
    if (parallelTable != null && parallelTable.parallelismHint() != null) {
        parallelismHint = parallelTable.parallelismHint();
    }
    final Table table = scan.getTable().unwrap(Table.class);
    switch(table.getJdbcTableType()) {
        case STREAM:
            return new TridentStreamScanRel(scan.getCluster(), scan.getTraitSet().replace(TridentLogicalConvention.INSTANCE), scan.getTable(), parallelismHint);
        default:
            throw new IllegalArgumentException(String.format("Unsupported table type: %s", table.getJdbcTableType()));
    }
}
Also used : ParallelStreamableTable(org.apache.storm.sql.calcite.ParallelStreamableTable) TableScan(org.apache.calcite.rel.core.TableScan) EnumerableTableScan(org.apache.calcite.adapter.enumerable.EnumerableTableScan) ParallelStreamableTable(org.apache.storm.sql.calcite.ParallelStreamableTable) Table(org.apache.calcite.schema.Table) TridentStreamScanRel(org.apache.storm.sql.planner.trident.rel.TridentStreamScanRel)

Example 8 with TableScan

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

the class PlanCompiler method printMain.

private void printMain(PrintWriter pw, RelNode root) {
    Set<TableScan> tables = new HashSet<>();
    pw.print(INITIALIZER_PROLOGUE);
    chainOperators(pw, root, tables);
    for (TableScan n : tables) {
        String escaped = CompilerUtil.escapeJavaString(Joiner.on('.').join(n.getTable().getQualifiedName()), true);
        String r = NEW_LINE_JOINER.join("    if (!data.containsKey(%1$s))", "      throw new RuntimeException(\"Cannot find table \" + %1$s);", "  data.get(%1$s).open(CTX_%2$d);", "");
        pw.print(String.format(r, escaped, n.getId()));
    }
    pw.print("  }\n");
}
Also used : TableScan(org.apache.calcite.rel.core.TableScan) HashSet(java.util.HashSet)

Example 9 with TableScan

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

the class HiveMaterializedViewFilterScanRule method onMatch.

//~ Methods ----------------------------------------------------------------
public void onMatch(RelOptRuleCall call) {
    final Project project = call.rel(0);
    final Filter filter = call.rel(1);
    final TableScan scan = call.rel(2);
    apply(call, project, filter, scan);
}
Also used : Project(org.apache.calcite.rel.core.Project) TableScan(org.apache.calcite.rel.core.TableScan) Filter(org.apache.calcite.rel.core.Filter)

Example 10 with TableScan

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

the class SubstitutionVisitor method toMutable.

private static MutableRel toMutable(RelNode rel) {
    if (rel instanceof TableScan) {
        return MutableScan.of((TableScan) rel);
    }
    if (rel instanceof Values) {
        return MutableValues.of((Values) rel);
    }
    if (rel instanceof Project) {
        final Project project = (Project) rel;
        final MutableRel input = toMutable(project.getInput());
        return MutableProject.of(input, project.getProjects(), project.getRowType().getFieldNames());
    }
    if (rel instanceof Filter) {
        final Filter filter = (Filter) rel;
        final MutableRel input = toMutable(filter.getInput());
        return MutableFilter.of(input, filter.getCondition());
    }
    if (rel instanceof Aggregate) {
        final Aggregate aggregate = (Aggregate) rel;
        final MutableRel input = toMutable(aggregate.getInput());
        return MutableAggregate.of(input, aggregate.indicator, aggregate.getGroupSet(), aggregate.getGroupSets(), aggregate.getAggCallList());
    }
    if (rel instanceof Join) {
        final Join join = (Join) rel;
        final MutableRel left = toMutable(join.getLeft());
        final MutableRel right = toMutable(join.getRight());
        return MutableJoin.of(join.getCluster(), left, right, join.getCondition(), join.getJoinType(), join.getVariablesSet());
    }
    if (rel instanceof Sort) {
        final Sort sort = (Sort) rel;
        final MutableRel input = toMutable(sort.getInput());
        return MutableSort.of(input, sort.getCollation(), sort.offset, sort.fetch);
    }
    throw new RuntimeException("cannot translate " + rel + " to MutableRel");
}
Also used : TableScan(org.apache.calcite.rel.core.TableScan) Project(org.apache.calcite.rel.core.Project) Filter(org.apache.calcite.rel.core.Filter) Values(org.apache.calcite.rel.core.Values) LogicalJoin(org.apache.calcite.rel.logical.LogicalJoin) Join(org.apache.calcite.rel.core.Join) LogicalSort(org.apache.calcite.rel.logical.LogicalSort) Sort(org.apache.calcite.rel.core.Sort) Aggregate(org.apache.calcite.rel.core.Aggregate) LogicalAggregate(org.apache.calcite.rel.logical.LogicalAggregate)

Aggregations

TableScan (org.apache.calcite.rel.core.TableScan)13 RelOptRuleCall (org.apache.calcite.plan.RelOptRuleCall)4 GroupScan (org.apache.drill.exec.physical.base.GroupScan)4 DrillFilterRel (org.apache.drill.exec.planner.logical.DrillFilterRel)4 DrillScanRel (org.apache.drill.exec.planner.logical.DrillScanRel)4 PlannerSettings (org.apache.drill.exec.planner.physical.PlannerSettings)4 RelNode (org.apache.calcite.rel.RelNode)3 Filter (org.apache.calcite.rel.core.Filter)3 Project (org.apache.calcite.rel.core.Project)3 HashSet (java.util.HashSet)2 EnumerableTableScan (org.apache.calcite.adapter.enumerable.EnumerableTableScan)2 Join (org.apache.calcite.rel.core.Join)2 FileGroupScan (org.apache.drill.exec.physical.base.FileGroupScan)2 ParquetPartitionDescriptor (org.apache.drill.exec.planner.ParquetPartitionDescriptor)2 DrillProjectRel (org.apache.drill.exec.planner.logical.DrillProjectRel)2 PruneScanRule (org.apache.drill.exec.planner.logical.partition.PruneScanRule)2 HivePartitionDescriptor (org.apache.drill.exec.planner.sql.HivePartitionDescriptor)2 HiveScan (org.apache.drill.exec.store.hive.HiveScan)2 ParquetGroupScan (org.apache.drill.exec.store.parquet.ParquetGroupScan)2 FieldSchema (org.apache.hadoop.hive.metastore.api.FieldSchema)2