@Override public DataType getValueType() { return subQueryNode.getOutSchema().getColumn(0).getDataType(); }
@Override public Type getValueType() { return TypeConverter.convert(subQueryNode.getOutSchema().getColumn(0).getDataType()); }
private EvalNode buildJoinCondition(EvalNode leftField, TableSubQueryNode subQueryNode) { FieldEval rightField = new FieldEval(subQueryNode.getOutSchema().getColumn(0)); return new BinaryEval(EvalType.EQUAL, leftField, rightField); }
private EvalNode buildJoinCondition(EvalNode leftField, TableSubQueryNode subQueryNode) { FieldEval rightField = new FieldEval(subQueryNode.getOutSchema().getColumn(0)); return new BinaryEval(EvalType.EQUAL, leftField, rightField); }
@Override public PlanString getPlanString() { PlanString planStr = new PlanString(this); planStr.appendTitle(" as ").appendTitle(tableName); if (hasTargets()) { StringBuilder sb = new StringBuilder("Targets: "); for (int i = 0; i < targets.size(); i++) { sb.append(targets.get(i)); if( i < targets.size() - 1) { sb.append(", "); } } planStr.addExplan(sb.toString()); if (getOutSchema() != null) { planStr.addExplan("out schema: " + getOutSchema().toString()); } if (getInSchema() != null) { planStr.addExplan("in schema: " + getInSchema().toString()); } } return planStr; }
@Override public PlanString getPlanString() { PlanString planStr = new PlanString(this); planStr.appendTitle(" as ").appendTitle(tableName); if (hasTargets()) { StringBuilder sb = new StringBuilder("Targets: "); for (int i = 0; i < targets.length; i++) { sb.append(targets[i]); if( i < targets.length - 1) { sb.append(", "); } } planStr.addExplan(sb.toString()); if (getOutSchema() != null) { planStr.addExplan("out schema: " + getOutSchema().toString()); } if (getInSchema() != null) { planStr.addExplan("in schema: " + getInSchema().toString()); } } return planStr; }
@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; }
public void init(String tableName, LogicalNode subQuery) { this.tableName = tableName; if (subQuery != null) { this.subQuery = subQuery; setOutSchema(SchemaUtil.clone(this.subQuery.getOutSchema())); setInSchema(SchemaUtil.clone(this.subQuery.getOutSchema())); getInSchema().setQualifier(this.tableName); getOutSchema().setQualifier(this.tableName); } }
public void init(String tableName, LogicalNode subQuery) { this.tableName = tableName; if (subQuery != null) { this.subQuery = subQuery; setOutSchema(SchemaUtil.clone(this.subQuery.getOutSchema())); setInSchema(SchemaUtil.clone(this.subQuery.getOutSchema())); getInSchema().setQualifier(this.tableName); getOutSchema().setQualifier(this.tableName); } }
if (copy.getInSchema().containsAll(copy.getOutSchema().getRootColumns())) { for (Target eachTarget : copy.getTargets()) { Set<Column> columns = EvalTreeUtil.findUniqueColumns(eachTarget.getEvalTree());
if (copy.getInSchema().containsAll(copy.getOutSchema().getRootColumns())) { for (Target eachTarget : copy.getTargets()) { Set<Column> columns = EvalTreeUtil.findUniqueColumns(eachTarget.getEvalTree());
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; }
currentBlock.addRelation(setOpTableSubQueryNode); Schema setOpSchema = setOpTableSubQueryNode.getOutSchema(); Target[] setOpTarget = setOpTableSubQueryNode.getTargets();
currentBlock.addRelation(setOpTableSubQueryNode); Schema setOpSchema = setOpTableSubQueryNode.getOutSchema(); List<Target> setOpTarget = setOpTableSubQueryNode.getTargets();