@Override public LogicalNode visitTableSubQuery(CompilationContext context, LogicalPlan plan, LogicalPlan.QueryBlock block, TableSubQueryNode node, Stack<LogicalNode> stack) throws TajoException { stack.push(node); visit(context, plan, null, node.getSubQuery(), stack); stack.pop(); if (node.hasTargets()) { for (Target target : node.getTargets()) { compileIfAbsent(context, node.getLogicalSchema(), target.getEvalTree()); } } return node; }
@Override public LogicalNode visitTableSubQuery(CompilationContext context, LogicalPlan plan, LogicalPlan.QueryBlock block, TableSubQueryNode node, Stack<LogicalNode> stack) throws TajoException { stack.push(node); visit(context, plan, null, node.getSubQuery(), stack); stack.pop(); if (node.hasTargets()) { for (Target target : node.getTargets()) { compileIfAbsent(context, node.getLogicalSchema(), target.getEvalTree()); } } return node; }
@Override public LogicalNode visitTableSubQuery(Context context, LogicalPlan plan, LogicalPlan.QueryBlock block, TableSubQueryNode node, Stack<LogicalNode> stack) throws TajoException { super.visitTableSubQuery(context, plan, block, node, stack); if (node.hasTargets()) { for (Target target : node.getTargets()) { ExprsVerifier.verify(context.state, node, target.getEvalTree()); } } verifyProjectableOutputSchema(context, node); return node; }
@Override public LogicalNode visitTableSubQuery(Context context, LogicalPlan plan, LogicalPlan.QueryBlock block, TableSubQueryNode node, Stack<LogicalNode> stack) throws TajoException { super.visitTableSubQuery(context, plan, block, node, stack); if (node.hasTargets()) { for (Target target : node.getTargets()) { ExprsVerifier.verify(context.state, node, target.getEvalTree()); } } verifyProjectableOutputSchema(context, node); return node; }
@Override public LogicalNode visitTableSubQuery(Context upperContext, LogicalPlan plan, LogicalPlan.QueryBlock block, TableSubQueryNode node, Stack<LogicalNode> stack) throws TajoException { Context childContext = new Context(plan, upperContext.requiredSet); stack.push(node); LogicalNode child = super.visitTableSubQuery(childContext, plan, block, node, stack); node.setSubQuery(child); stack.pop(); Target [] targets; if (node.hasTargets()) { targets = node.getTargets(); } else { targets = PlannerUtil.schemaToTargets(node.getOutSchema()); } LinkedHashSet<Target> projectedTargets = Sets.newLinkedHashSet(); for (Iterator<Target> it = getFilteredTarget(targets, upperContext.requiredSet); it.hasNext();) { Target target = it.next(); upperContext.addExpr(target); } for (Iterator<Target> it = upperContext.targetListMgr.getFilteredTargets(upperContext.requiredSet); it.hasNext();) { Target target = it.next(); if (LogicalPlanner.checkIfBeEvaluatedAtRelation(block, target.getEvalTree(), node)) { projectedTargets.add(target); upperContext.targetListMgr.markAsEvaluated(target); } } node.setTargets(projectedTargets.toArray(new Target[projectedTargets.size()])); LogicalPlanner.verifyProjectedFields(block, node); return node; }
@Override public LogicalNode visitTableSubQuery(Context upperContext, LogicalPlan plan, LogicalPlan.QueryBlock block, TableSubQueryNode node, Stack<LogicalNode> stack) throws TajoException { Context childContext = new Context(plan, upperContext.requiredSet); stack.push(node); LogicalNode child = super.visitTableSubQuery(childContext, plan, block, node, stack); node.setSubQuery(child); stack.pop(); List<Target> targets; if (node.hasTargets()) { targets = node.getTargets(); } else { targets = PlannerUtil.schemaToTargets(node.getOutSchema()); } LinkedHashSet<Target> projectedTargets = Sets.newLinkedHashSet(); for (Iterator<Target> it = getFilteredTarget(targets, upperContext.requiredSet); it.hasNext();) { Target target = it.next(); upperContext.addExpr(target); } for (Iterator<Target> it = upperContext.targetListMgr.getFilteredTargets(upperContext.requiredSet); it.hasNext();) { Target target = it.next(); if (LogicalPlanner.checkIfBeEvaluatedAtRelation(block, target.getEvalTree(), node)) { projectedTargets.add(target); upperContext.targetListMgr.markAsEvaluated(target); } } node.setTargets(new ArrayList<>(projectedTargets)); LogicalPlanner.verifyProjectedFields(block, node); return node; }
@Override public LogicalNode visitTableSubQuery(SerializeContext context, LogicalPlan plan, LogicalPlan.QueryBlock block, TableSubQueryNode node, Stack<LogicalNode> stack) throws TajoException { super.visitTableSubQuery(context, plan, block, node, stack); int [] childIds = registerGetChildIds(context, node); PlanProto.TableSubQueryNode.Builder builder = PlanProto.TableSubQueryNode.newBuilder(); builder.setChildSeq(childIds[0]); builder.setTableName(node.getTableName()); if (node.hasTargets()) { builder.addAllTargets(ProtoUtil.<PlanProto.Target>toProtoObjects(node.getTargets().toArray(new ProtoObject[node.getTargets().size()]))); } builder.setNameResolveBase(node.isNameResolveBase()); PlanProto.LogicalNode.Builder nodeBuilder = createNodeBuilder(context, node); nodeBuilder.setTableSubQuery(builder); context.treeBuilder.addNodes(nodeBuilder); return node; }
for (Target eachTarget : copy.getTargets()) { Set<Column> columns = EvalTreeUtil.findUniqueColumns(eachTarget.getEvalTree()); if (copy.getInSchema().containsAll(columns)) { List<Target> targets = leftMostSubQueryNode.getTargets(); int[] targetMappings = new int[targets.size()]; for (int i = 0; i < targets.size(); i++) { continue; List<Target> eachNodeTargets = eachNode.getTargets(); if (eachNodeTargets.size() != targetMappings.length) { throw new TajoInternalError("Union query can't have different number of target columns.");
for (Target eachTarget : copy.getTargets()) { Set<Column> columns = EvalTreeUtil.findUniqueColumns(eachTarget.getEvalTree()); if (copy.getInSchema().containsAll(columns)) { Target[] targets = leftMostSubQueryNode.getTargets(); int[] targetMappings = new int[targets.length]; for (int i = 0; i < targets.length; i++) { continue; Target[] eachNodeTargets = eachNode.getTargets(); if (eachNodeTargets.length != targetMappings.length) { throw new TajoInternalError("Union query can't have different number of target columns.");
@Override public LogicalNode visitTableSubQuery(SerializeContext context, LogicalPlan plan, LogicalPlan.QueryBlock block, TableSubQueryNode node, Stack<LogicalNode> stack) throws TajoException { super.visitTableSubQuery(context, plan, block, node, stack); int [] childIds = registerGetChildIds(context, node); PlanProto.TableSubQueryNode.Builder builder = PlanProto.TableSubQueryNode.newBuilder(); builder.setChildSeq(childIds[0]); builder.setTableName(node.getTableName()); if (node.hasTargets()) { builder.addAllTargets(ProtoUtil.<PlanProto.Target>toProtoObjects(node.getTargets())); } builder.setNameResolveBase(node.isNameResolveBase()); PlanProto.LogicalNode.Builder nodeBuilder = createNodeBuilder(context, node); nodeBuilder.setTableSubQuery(builder); context.treeBuilder.addNodes(nodeBuilder); return node; }
private ProjectionNode makeProjectionForInsertUnion(PlanContext context, InsertNode insertNode) { LogicalNode child = insertNode.getChild(); // add (projection - subquery) to RootBlock and create new QueryBlock for UnionNode TableSubQueryNode subQueryNode = context.plan.createNode(TableSubQueryNode.class); subQueryNode.init(context.queryBlock.getName(), child); subQueryNode.setTargets(PlannerUtil.schemaToTargets(subQueryNode.getOutSchema())); ProjectionNode projectionNode = context.plan.createNode(ProjectionNode.class); projectionNode.setChild(subQueryNode); projectionNode.setInSchema(subQueryNode.getInSchema()); projectionNode.setTargets(subQueryNode.getTargets()); context.queryBlock.registerNode(projectionNode); context.queryBlock.registerNode(subQueryNode); // add child QueryBlock to the UnionNode's QueryBlock UnionNode unionNode = (UnionNode)child; context.queryBlock.unregisterNode(unionNode); QueryBlock unionBlock = context.plan.newQueryBlock(); unionBlock.registerNode(unionNode); unionBlock.setRoot(unionNode); QueryBlock leftBlock = context.plan.getBlock(unionNode.getLeftChild()); QueryBlock rightBlock = context.plan.getBlock(unionNode.getRightChild()); context.plan.disconnectBlocks(leftBlock, context.queryBlock); context.plan.disconnectBlocks(rightBlock, context.queryBlock); context.plan.connectBlocks(unionBlock, context.queryBlock, BlockType.TableSubQuery); context.plan.connectBlocks(leftBlock, unionBlock, BlockType.TableSubQuery); context.plan.connectBlocks(rightBlock, unionBlock, BlockType.TableSubQuery); // set InsertNode's child with ProjectionNode which is created. insertNode.setChild(projectionNode); return projectionNode; }
private ProjectionNode makeProjectionForInsertUnion(PlanContext context, InsertNode insertNode) { LogicalNode child = insertNode.getChild(); // add (projection - subquery) to RootBlock and create new QueryBlock for UnionNode TableSubQueryNode subQueryNode = context.plan.createNode(TableSubQueryNode.class); subQueryNode.init(context.queryBlock.getName(), child); subQueryNode.setTargets(PlannerUtil.schemaToTargets(subQueryNode.getOutSchema())); ProjectionNode projectionNode = context.plan.createNode(ProjectionNode.class); projectionNode.setChild(subQueryNode); projectionNode.setInSchema(subQueryNode.getInSchema()); projectionNode.setTargets(subQueryNode.getTargets()); context.queryBlock.registerNode(projectionNode); context.queryBlock.registerNode(subQueryNode); // add child QueryBlock to the UnionNode's QueryBlock UnionNode unionNode = (UnionNode)child; context.queryBlock.unregisterNode(unionNode); QueryBlock unionBlock = context.plan.newQueryBlock(); unionBlock.registerNode(unionNode); unionBlock.setRoot(unionNode); QueryBlock leftBlock = context.plan.getBlock(unionNode.getLeftChild()); QueryBlock rightBlock = context.plan.getBlock(unionNode.getRightChild()); context.plan.disconnectBlocks(leftBlock, context.queryBlock); context.plan.disconnectBlocks(rightBlock, context.queryBlock); context.plan.connectBlocks(unionBlock, context.queryBlock, BlockType.TableSubQuery); context.plan.connectBlocks(leftBlock, unionBlock, BlockType.TableSubQuery); context.plan.connectBlocks(rightBlock, unionBlock, BlockType.TableSubQuery); // set InsertNode's child with ProjectionNode which is created. insertNode.setChild(projectionNode); return projectionNode; }
Target[] setOpTarget = setOpTableSubQueryNode.getTargets();
List<Target> setOpTarget = setOpTableSubQueryNode.getTargets();