@Test public final void testFindTopNode() throws CloneNotSupportedException, PlanningException { Expr expr = analyzer.parse(TestLogicalPlanner.QUERIES[1]); LogicalNode plan = planner.createPlan(expr).getRootBlock().getRoot(); assertEquals(NodeType.ROOT, plan.getType()); LogicalRootNode root = (LogicalRootNode) plan; TestLogicalNode.testCloneLogicalNode(root); assertEquals(NodeType.PROJECTION, root.getChild().getType()); ProjectionNode projNode = (ProjectionNode) root.getChild(); assertEquals(NodeType.JOIN, projNode.getChild().getType()); JoinNode joinNode = (JoinNode) projNode.getChild(); assertEquals(NodeType.SCAN, joinNode.getLeftChild().getType()); ScanNode leftNode = (ScanNode) joinNode.getLeftChild(); assertEquals("employee", leftNode.getTableName()); assertEquals(NodeType.SCAN, joinNode.getRightChild().getType()); ScanNode rightNode = (ScanNode) joinNode.getRightChild(); assertEquals("dept", rightNode.getTableName()); LogicalNode node = PlannerUtil.findTopNode(root, NodeType.ROOT); assertEquals(NodeType.ROOT, node.getType()); node = PlannerUtil.findTopNode(root, NodeType.PROJECTION); assertEquals(NodeType.PROJECTION, node.getType()); node = PlannerUtil.findTopNode(root, NodeType.JOIN); assertEquals(NodeType.JOIN, node.getType()); node = PlannerUtil.findTopNode(root, NodeType.SCAN); assertEquals(NodeType.SCAN, node.getType()); }
public static <T extends LogicalNode> T findTopNode(LogicalNode node, NodeType type) { Preconditions.checkNotNull(node); Preconditions.checkNotNull(type); LogicalNodeFinder finder = new LogicalNodeFinder(type); node.preOrder(finder); if (finder.getFoundNodes().size() == 0) { return null; } return (T) finder.getFoundNodes().get(0); }
PlannerUtil { public static <T extends LogicalNode> T findTopNode(LogicalNode node, NodeType type) { Preconditions.checkNotNull(node); Preconditions.checkNotNull(type); LogicalNodeFinder finder = new LogicalNodeFinder(type); node.preOrder(finder); if (finder.getFoundNodes().size() == 0) { return null; } return (T) finder.getFoundNodes().get(0); } }
PlannerUtil { public static <T extends LogicalNode> T findTopNode(LogicalNode node, NodeType type) { Preconditions.checkNotNull(node); Preconditions.checkNotNull(type); LogicalNodeFinder finder = new LogicalNodeFinder(type); node.preOrder(finder); if (finder.getFoundNodes().size() == 0) { return null; } return (T) finder.getFoundNodes().get(0); }  }
PlannerUtil { public static <T extends LogicalNode> T findTopNode(LogicalNode node, NodeType type) { Preconditions.checkNotNull(node); Preconditions.checkNotNull(type); LogicalNodeFinder finder = new LogicalNodeFinder(type); node.preOrder(finder); if (finder.getFoundNodes().size() == 0) { return null; } return (T) finder.getFoundNodes().get(0); }  static boolean checkIfDDLPlan(LogicalNode node); static String [] getRelationLineage(LogicalNode from); static Collection<String> getRelationLineageWithinQueryBlock(LogicalPlan plan, LogicalNode from); static LogicalNode deleteNode(LogicalNode parent, LogicalNode tobeRemoved); static void replaceNode(LogicalPlan plan, LogicalNode startNode, LogicalNode oldNode, LogicalNode newNode); static void replaceNode(LogicalNode plan, LogicalNode newNode, NodeType type); static T findTopNode(LogicalNode node, NodeType type); static T findMostBottomNode(LogicalNode node, NodeType type); static LogicalNode [] findAllNodes(LogicalNode node, NodeType...type); static T findTopParentNode(LogicalNode node, NodeType type); static void schemaToTargets(Schema schema, Target [] targets); static Target[] schemaToTargets(Schema schema); static Target[] schemaToTargetsWithGeneratedFields(Schema schema); static SortSpec[] schemaToSortSpecs(Schema schema); static SortSpec[] schemaToSortSpecs(Column [] columns); static SortSpec [] columnsToSortSpec(Collection<Column> columns); static Schema sortSpecsToSchema(SortSpec[] sortSpecs); static boolean isJoinQual(EvalNode qual); static SortSpec[][] getSortKeysFromJoinQual(EvalNode joinQual, Schema outer, Schema inner); static TupleComparator[] getComparatorsFromJoinQual(EvalNode joinQual, Schema leftSchema, Schema rightSchema); static Column [][] joinJoinKeyForEachTable(EvalNode joinQual, Schema leftSchema, Schema rightSchema); static List<Column []> getJoinKeyPairs(EvalNode joinQual, Schema leftSchema, Schema rightSchema); static Schema targetToSchema(Collection<Target> targets); static Schema targetToSchema(Target[] targets); static Target [] stripTarget(Target [] sourceTargets); static T clone(LogicalPlan plan, LogicalNode node); static boolean isCommutativeJoin(JoinType joinType); static boolean existsAggregationFunction(Expr expr); static boolean existsDistinctAggregationFunction(Expr expr); static Collection<String> toQualifiedFieldNames(Collection<String> fieldNames, String qualifier); static SortSpec [] convertSortSpecs(Collection<CatalogProtos.SortSpecProto> sortSpecProtos); static String buildExplainString(LogicalNode node); }
PlannerUtil { public static <T extends LogicalNode> T findTopNode(LogicalNode node, NodeType type) { Preconditions.checkNotNull(node); Preconditions.checkNotNull(type); LogicalNodeFinder finder = new LogicalNodeFinder(type); node.preOrder(finder); if (finder.getFoundNodes().size() == 0) { return null; } return (T) finder.getFoundNodes().get(0); }  static boolean checkIfDDLPlan(LogicalNode node); static String [] getRelationLineage(LogicalNode from); static Collection<String> getRelationLineageWithinQueryBlock(LogicalPlan plan, LogicalNode from); static LogicalNode deleteNode(LogicalNode parent, LogicalNode tobeRemoved); static void replaceNode(LogicalPlan plan, LogicalNode startNode, LogicalNode oldNode, LogicalNode newNode); static void replaceNode(LogicalNode plan, LogicalNode newNode, NodeType type); static T findTopNode(LogicalNode node, NodeType type); static T findMostBottomNode(LogicalNode node, NodeType type); static LogicalNode [] findAllNodes(LogicalNode node, NodeType...type); static T findTopParentNode(LogicalNode node, NodeType type); static void schemaToTargets(Schema schema, Target [] targets); static Target[] schemaToTargets(Schema schema); static Target[] schemaToTargetsWithGeneratedFields(Schema schema); static SortSpec[] schemaToSortSpecs(Schema schema); static SortSpec[] schemaToSortSpecs(Column [] columns); static SortSpec [] columnsToSortSpec(Collection<Column> columns); static Schema sortSpecsToSchema(SortSpec[] sortSpecs); static boolean isJoinQual(EvalNode qual); static SortSpec[][] getSortKeysFromJoinQual(EvalNode joinQual, Schema outer, Schema inner); static TupleComparator[] getComparatorsFromJoinQual(EvalNode joinQual, Schema leftSchema, Schema rightSchema); static Column [][] joinJoinKeyForEachTable(EvalNode joinQual, Schema leftSchema, Schema rightSchema); static List<Column []> getJoinKeyPairs(EvalNode joinQual, Schema leftSchema, Schema rightSchema); static Schema targetToSchema(Collection<Target> targets); static Schema targetToSchema(Target[] targets); static Target [] stripTarget(Target [] sourceTargets); static T clone(LogicalPlan plan, LogicalNode node); static boolean isCommutativeJoin(JoinType joinType); static boolean existsAggregationFunction(Expr expr); static boolean existsDistinctAggregationFunction(Expr expr); static Collection<String> toQualifiedFieldNames(Collection<String> fieldNames, String qualifier); static SortSpec [] convertSortSpecs(Collection<CatalogProtos.SortSpecProto> sortSpecProtos); static String buildExplainString(LogicalNode node);  }