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);
}
}
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);
}
}
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;
}
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));
}
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);
}
}
Aggregations