private static UnionNode convertUnion(Map<Integer, LogicalNode> nodeMap, PlanProto.LogicalNode protoNode) { PlanProto.UnionNode unionProto = protoNode.getUnion(); UnionNode union = new UnionNode(protoNode.getNodeId()); union.setInSchema(convertSchema(protoNode.getInSchema())); union.setOutSchema(convertSchema(protoNode.getOutSchema())); union.setLeftChild(nodeMap.get(unionProto.getLeftChildSeq())); union.setRightChild(nodeMap.get(unionProto.getRightChildSeq())); return union; }
private static UnionNode convertUnion(Map<Integer, LogicalNode> nodeMap, PlanProto.LogicalNode protoNode) { PlanProto.UnionNode unionProto = protoNode.getUnion(); UnionNode union = new UnionNode(protoNode.getNodeId()); union.setInSchema(convertSchema(protoNode.getInSchema())); union.setOutSchema(convertSchema(protoNode.getOutSchema())); union.setLeftChild(nodeMap.get(unionProto.getLeftChildSeq())); union.setRightChild(nodeMap.get(unionProto.getRightChildSeq())); return union; }
unionNode.setLeftChild(left); unionNode.setRightChild(GlobalPlanner.buildInputExecutor(plan.getLogicalPlan(), plan.getChannel(unionScans.get(i), current.getId())));
unionNode.setLeftChild(left); unionNode.setRightChild(GlobalPlanner.buildInputExecutor(plan.getLogicalPlan(), plan.getChannel(unionScans.get(i), current.getId())));
@Override public LogicalNode visitUnion(LogicalPlanner.PlanContext ctx, Stack<Expr> stack, SetOperation expr) throws TajoException { LogicalPlan.QueryBlock leftBlock = ctx.getPlan().newQueryBlock(); LogicalPlanner.PlanContext leftContext = new LogicalPlanner.PlanContext(ctx, leftBlock); LogicalNode leftChild = visit(leftContext, new Stack<>(), expr.getLeft()); leftBlock.setRoot(leftChild); ctx.getQueryBlock().registerExprWithNode(expr.getLeft(), leftChild); LogicalPlan.QueryBlock rightBlock = ctx.getPlan().newQueryBlock(); LogicalPlanner.PlanContext rightContext = new LogicalPlanner.PlanContext(ctx, rightBlock); LogicalNode rightChild = visit(rightContext, new Stack<>(), expr.getRight()); rightBlock.setRoot(rightChild); ctx.getQueryBlock().registerExprWithNode(expr.getRight(), rightChild); UnionNode unionNode = new UnionNode(ctx.getPlan().newPID()); unionNode.setLeftChild(leftChild); unionNode.setRightChild(rightChild); unionNode.setInSchema(leftChild.getOutSchema()); unionNode.setOutSchema(leftChild.getOutSchema()); unionNode.setDistinct(expr.isDistinct()); return unionNode; }
@Override public LogicalNode visitUnion(LogicalPlanner.PlanContext ctx, Stack<Expr> stack, SetOperation expr) throws TajoException { LogicalPlan.QueryBlock leftBlock = ctx.getPlan().newQueryBlock(); LogicalPlanner.PlanContext leftContext = new LogicalPlanner.PlanContext(ctx, leftBlock); LogicalNode leftChild = visit(leftContext, new Stack<Expr>(), expr.getLeft()); leftBlock.setRoot(leftChild); ctx.getQueryBlock().registerExprWithNode(expr.getLeft(), leftChild); LogicalPlan.QueryBlock rightBlock = ctx.getPlan().newQueryBlock(); LogicalPlanner.PlanContext rightContext = new LogicalPlanner.PlanContext(ctx, rightBlock); LogicalNode rightChild = visit(rightContext, new Stack<Expr>(), expr.getRight()); rightBlock.setRoot(rightChild); ctx.getQueryBlock().registerExprWithNode(expr.getRight(), rightChild); UnionNode unionNode = new UnionNode(ctx.getPlan().newPID()); unionNode.setLeftChild(leftChild); unionNode.setRightChild(rightChild); unionNode.setInSchema(leftChild.getOutSchema()); unionNode.setOutSchema(leftChild.getOutSchema()); unionNode.setDistinct(expr.isDistinct()); return unionNode; }
@Test public final void testUnionPlan() throws IOException, TajoException, CloneNotSupportedException { FileFragment[] frags = FileTablespace.splitNG(conf, "default.employee", employee.getMeta(), new Path(employee.getUri()), Integer.MAX_VALUE); Path workDir = CommonTestingUtil.getTestDir(TajoTestingCluster.DEFAULT_TEST_DIRECTORY + "/testUnionPlan"); TaskAttemptContext ctx = new TaskAttemptContext(new QueryContext(conf), LocalTajoTestingUtility.newTaskAttemptId(masterPlan), new FileFragment[] { frags[0] }, workDir); ctx.setEnforcer(new Enforcer()); Expr context = analyzer.parse(QUERIES[0]); LogicalPlan plan = planner.createPlan(defaultContext, context); LogicalNode rootNode = optimizer.optimize(plan); LogicalRootNode root = (LogicalRootNode) rootNode; UnionNode union = plan.createNode(UnionNode.class); union.setLeftChild((LogicalNode) root.getChild().clone()); union.setRightChild((LogicalNode) root.getChild().clone()); root.setChild(union); PhysicalPlanner phyPlanner = new PhysicalPlannerImpl(conf); PhysicalExec exec = phyPlanner.createPlan(ctx, root); int count = 0; exec.init(); while(exec.next() != null) { count++; } exec.close(); assertEquals(200, count); }