public void visit( RelNode node, int ordinal, RelNode parent) { if (node instanceof JdbcHiveTableScan && tmpJdbcHiveTableScan [0] == null) { tmpJdbcHiveTableScan [0] = (JdbcHiveTableScan) node; } else { super.visit(node, ordinal, parent); } } }.go(this);
new RelVisitor() { @Override public void visit(RelNode node, int ordinal, RelNode parent) { new RelVisitor() { @Override public void visit(RelNode node, int ordinal, RelNode parent) {
public static Set<List<String>> findTables(final RelNode node) { final Set<List<String>> usedTables = Sets.newLinkedHashSet(); final RelVisitor visitor = new RelVisitor() { @Override public void visit(final RelNode node, final int ordinal, final RelNode parent) { if (node instanceof TableScan) { usedTables.add(node.getTable().getQualifiedName()); } super.visit(node, ordinal, parent); } }; visitor.go(node); return usedTables; }
/** * Sets a {@link RelVisitor} going on a given relational expression, and * returns the result. */ public static void go( RelVisitor visitor, RelNode p) { try { visitor.go(p); } catch (Exception e) { throw new RuntimeException("while visiting tree", e); } }
@Override public void visit(RelNode node, int ordinal, RelNode parent) { if (node instanceof TableScan || node instanceof Filter || node instanceof Project || node instanceof Join) { // We can continue super.visit(node, ordinal, parent); } else if (node instanceof Aggregate && containsAggregate) { // We can continue super.visit(node, ordinal, parent); } else { throw new ReturnedValue(false); } } }.go(union.getInput(0));
/** * Sets a {@link RelVisitor} going on a given relational expression, and * returns the result. */ public static void go( RelVisitor visitor, RelNode p) { try { visitor.go(p); } catch (Exception e) { throw new RuntimeException("while visiting tree", e); } }
@Override public void visit(RelNode node, int ordinal, RelNode parent) { if (node instanceof Project || node instanceof Filter || node instanceof TableScan) { // We can continue super.visit(node, ordinal, parent); } else { throw new ReturnedValue(false); } }
visitor.go(root);
@Override public void visit(RelNode node, int ordinal, RelNode parent) { if (node instanceof TableScan) { TableScan ts = (TableScan) node; tablesUsed.add(((RelOptHiveTable) ts.getTable()).getHiveTableMD().getFullyQualifiedName()); } super.visit(node, ordinal, parent); } }.go(plan);
visitor.go(root);
@Override public void visit(RelNode node, int ordinal, RelNode parent) { if (node instanceof HepRelVertex) { node = ((HepRelVertex) node).getCurrentRel(); } if (node instanceof TableScan) { simpleTree = true; } else if (node instanceof Project) { simpleTree = isSimple((Project) node); } else if (node instanceof Filter) { simpleTree = isSimple((Filter) node, mq); } else { simpleTree = false; } if (simpleTree) { super.visit(node, ordinal, parent); } }
private RelNode transformToDruidPlan(RelNode root) { RelOptPlanner plan = root.getCluster().getPlanner(); final RelVisitor visitor = new RelVisitor() { @Override public void visit(RelNode node, int ordinal, RelNode parent) { if (node instanceof TableScan) { final RelOptCluster cluster = node.getCluster(); final RelOptTable.ToRelContext context = RelOptUtil.getContext(cluster); final RelNode r = node.getTable().toRel(context); plan.registerClass(r); } super.visit(node, ordinal, parent); } }; visitor.go(root); Program program = Programs.standard(); RelTraitSet traits = plan.emptyTraitSet().replace(EnumerableConvention.INSTANCE); return program.run(plan, root, traits, ImmutableList.<RelOptMaterialization>of(), ImmutableList.<RelOptLattice>of()); }
@Override public void visit(RelNode node, int ordinal, RelNode parent) { if (node instanceof Aggregate) { this.containsAggregate = true; // Aggregate mode - it should be followed by union // that we need to analyze RelNode input = node.getInput(0); if (input instanceof Union) { check((Union) input); } } else if (node instanceof Union) { // Non aggregate mode - analyze union operator check((Union) node); } else if (node instanceof Project) { // Project operator, we can continue super.visit(node, ordinal, parent); } throw new ReturnedValue(false); }
relVisitor.go(relNode);
@Override public void visit(RelNode node, int ordinal, RelNode parent) { if (node instanceof HepRelVertex) { node = ((HepRelVertex) node).getCurrentRel(); } if (node instanceof TableScan) { simpleTree = true; } else if (node instanceof Project) { simpleTree = isSimple((Project) node); nonFilteringTree &= simpleTree; } else if (node instanceof Filter) { // Remove is not null from condition if it does not filter anything. Filter filterOp = (Filter) node; List<RexNode> conjs = extractFilterPreds(filterOp); ImmutableBitSet condBits = RelOptUtil.InputFinder.bits(conjs, null); // For simple tree, we want to know whether filter is only on // key columns. simpleTree = isSimple(condBits, filterOp, mq); nonFilteringTree &= conjs.isEmpty(); } else { simpleTree = false; nonFilteringTree = false; } if (simpleTree) { super.visit(node, ordinal, parent); } }
visitor.go(root.rel);
@Override public void visit(RelNode node, int ordinal, RelNode parent) { if (node instanceof TableScan) { // We can continue // TODO: Need to check that this is the same MV that we are rebuilding RelOptHiveTable hiveTable = (RelOptHiveTable) node.getTable(); if (!hiveTable.getHiveTableMD().isMaterializedView()) { // If it is not a materialized view, we do not rewrite it throw new ReturnedValue(false); } if (containsAggregate && !AcidUtils.isFullAcidTable(hiveTable.getHiveTableMD())) { // If it contains an aggregate and it is not a full acid table, // we do not rewrite it (we need MERGE support) throw new ReturnedValue(false); } } else if (node instanceof Project) { // We can continue super.visit(node, ordinal, parent); } else { throw new ReturnedValue(false); } } }.go(union.getInput(1));
visitor.go(root.rel);
@Override public void visit(RelNode node, int ordinal, RelNode parent) { if (node instanceof FlattenRel) { found = true; } super.visit(node, ordinal, parent); } }
/** * Starts an iteration. */ public RelNode go(RelNode p) { this.root = p; visit(p, 0, null); return root; } }