QueryBlock leftBlock = context.plan.getBlockByExpr(setOperation.getLeft()); PlanContext leftContext = new PlanContext(context, leftBlock); stack.push(setOperation); LogicalNode leftChild = visit(leftContext, new Stack<Expr>(), setOperation.getLeft()); stack.pop(); QueryBlock rightBlock = context.plan.getBlockByExpr(setOperation.getRight()); PlanContext rightContext = new PlanContext(context, rightBlock); stack.push(setOperation); LogicalNode rightChild = visit(rightContext, new Stack<Expr>(), setOperation.getRight()); stack.pop(); if (setOperation.getType() == OpType.Union) { setOp = block.getNodeFromExpr(setOperation); } else if (setOperation.getType() == OpType.Except) { setOp = block.getNodeFromExpr(setOperation); } else if (setOperation.getType() == OpType.Intersect) { setOp = block.getNodeFromExpr(setOperation); } else { throw new TajoInternalError("Unknown set type: " + setOperation.getType());
@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 visitIntersect(ProcessorContext ctx, Stack<Expr> stack, SetOperation expr) throws TajoException { super.visitIntersect(ctx, stack, expr); IntersectNode node = getNodeFromExpr(ctx.planContext.getPlan(), expr); LogicalNode child = getNonRelationListExpr(ctx.planContext.getPlan(), expr.getLeft()); node.setInSchema(child.getOutSchema()); node.setOutSchema(node.getInSchema()); return node; }
@Override public Expr visitNon_join_query_term(Non_join_query_termContext ctx) { Expr current = visitNon_join_query_primary(ctx.non_join_query_primary()); Expr left; for (int i = 1; i < ctx.getChildCount(); ) { int idx = i; boolean distinct = true; if (ctx.getChild(idx) instanceof TerminalNode) { if (((TerminalNode) ctx.getChild(idx)).getSymbol().getType() == INTERSECT) { idx++; } if (ctx.getChild(idx) instanceof TerminalNode) { if (((TerminalNode) ctx.getChild(idx)).getSymbol().getType() == ALL) { distinct = false; idx++; } } Query_primaryContext queryPrimaryContext = (Query_primaryContext) ctx.getChild(idx); Expr right = visitQuery_primary(queryPrimaryContext); left = current; current = new SetOperation(OpType.Intersect, left, right, distinct); i += idx; } } return current; }
@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; }
@Override public LogicalNode visitExcept(ProcessorContext ctx, Stack<Expr> stack, SetOperation expr) throws TajoException { super.visitExcept(ctx, stack, expr); ExceptNode node = getNodeFromExpr(ctx.planContext.getPlan(), expr); LogicalNode child = getNonRelationListExpr(ctx.planContext.getPlan(), expr.getLeft()); node.setInSchema(child.getOutSchema()); node.setOutSchema(node.getInSchema()); return node; }
@Override public Expr visitNon_join_query_term(Non_join_query_termContext ctx) { Expr current = visitNon_join_query_primary(ctx.non_join_query_primary()); Expr left; for (int i = 1; i < ctx.getChildCount(); ) { int idx = i; boolean distinct = true; if (ctx.getChild(idx) instanceof TerminalNode) { if (((TerminalNode) ctx.getChild(idx)).getSymbol().getType() == INTERSECT) { idx++; } if (ctx.getChild(idx) instanceof TerminalNode) { if (((TerminalNode) ctx.getChild(idx)).getSymbol().getType() == ALL) { distinct = false; idx++; } } Query_primaryContext queryPrimaryContext = (Query_primaryContext) ctx.getChild(idx); Expr right = visitQuery_primary(queryPrimaryContext); left = current; current = new SetOperation(OpType.Intersect, left, right, distinct); i += idx; } } return current; }
QueryBlock leftBlock = context.plan.getBlockByExpr(setOperation.getLeft()); PlanContext leftContext = new PlanContext(context, leftBlock); stack.push(setOperation); LogicalNode leftChild = visit(leftContext, new Stack<>(), setOperation.getLeft()); stack.pop(); QueryBlock rightBlock = context.plan.getBlockByExpr(setOperation.getRight()); PlanContext rightContext = new PlanContext(context, rightBlock); stack.push(setOperation); LogicalNode rightChild = visit(rightContext, new Stack<>(), setOperation.getRight()); stack.pop(); if (setOperation.getType() == OpType.Union) { setOp = block.getNodeFromExpr(setOperation); } else if (setOperation.getType() == OpType.Except) { setOp = block.getNodeFromExpr(setOperation); } else if (setOperation.getType() == OpType.Intersect) { setOp = block.getNodeFromExpr(setOperation); } else { throw new TajoInternalError("Unknown set type: " + setOperation.getType());
@Override public LogicalNode visitIntersect(ProcessorContext ctx, Stack<Expr> stack, SetOperation expr) throws TajoException { super.visitIntersect(ctx, stack, expr); IntersectNode node = getNodeFromExpr(ctx.planContext.getPlan(), expr); LogicalNode child = getNonRelationListExpr(ctx.planContext.getPlan(), expr.getLeft()); node.setInSchema(child.getOutSchema()); node.setOutSchema(node.getInSchema()); return node; }
current = new SetOperation(operatorType, left, right, distinct);
@Override public LogicalNode visitUnion(ProcessorContext ctx, Stack<Expr> stack, SetOperation expr) throws TajoException { super.visitUnion(ctx, stack, expr); UnionNode node = getNodeFromExpr(ctx.planContext.getPlan(), expr); LogicalNode child = getNonRelationListExpr(ctx.planContext.getPlan(), expr.getLeft()); node.setInSchema(child.getOutSchema()); node.setOutSchema(node.getInSchema()); return node; }
current = new SetOperation(operatorType, left, right, distinct);
@Override public LogicalNode visitExcept(ProcessorContext ctx, Stack<Expr> stack, SetOperation expr) throws TajoException { super.visitExcept(ctx, stack, expr); ExceptNode node = getNodeFromExpr(ctx.planContext.getPlan(), expr); LogicalNode child = getNonRelationListExpr(ctx.planContext.getPlan(), expr.getLeft()); node.setInSchema(child.getOutSchema()); node.setOutSchema(node.getInSchema()); return node; }
@Override public LogicalNode visitUnion(ProcessorContext ctx, Stack<Expr> stack, SetOperation expr) throws TajoException { super.visitUnion(ctx, stack, expr); UnionNode node = getNodeFromExpr(ctx.planContext.getPlan(), expr); LogicalNode child = getNonRelationListExpr(ctx.planContext.getPlan(), expr.getLeft()); node.setInSchema(child.getOutSchema()); node.setOutSchema(node.getInSchema()); return node; }