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); } }
/** * 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); } }
visitor.go(root);
visitor.go(root);
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()); }
relVisitor.go(relNode);
visitor.go(root.rel);
visitor.go(root.rel);