@Override public Schema getLogicalSchema() { // an output schema can be determined by targets. So, an input schema of // TableSubQueryNode is only eligible for table schema. // // TODO - but, a derived table can have column alias. For that, we should improve here. // // example) select * from (select col1, col2, col3 from t1) view (c1, c2); return getInSchema(); }
@Override public Schema getLogicalSchema() { // an output schema can be determined by targets. So, an input schema of // TableSubQueryNode is only eligible for table schema. // // TODO - but, a derived table can have column alias. For that, we should improve here. // // example) select * from (select col1, col2, col3 from t1) view (c1, c2); return getInSchema(); }
@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; }
if (copy.getInSchema().containsAll(copy.getOutSchema().getRootColumns())) { for (Target eachTarget : copy.getTargets()) { Set<Column> columns = EvalTreeUtil.findUniqueColumns(eachTarget.getEvalTree()); if (copy.getInSchema().containsAll(columns)) { leftMostSubQueryNode = copy; break; throw new TajoInternalError("Target of a UnionNode's subquery should be FieldEval."); int index = leftMostSubQueryNode.getInSchema().getColumnId(targets.get(i).getNamedColumn().getQualifiedName()); if (index < 0) { index = leftMostSubQueryNode.getInSchema().getColumnId(column.getQualifiedName()); + "->" + leftMostSubQueryNode.getInSchema()); Column inColumn = eachNode.getInSchema().getColumn(targetMappings[i]); Target t = eachNodeTargets.get(i); t.setAlias(t.getNamedColumn().getQualifiedName());
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); } }
public void setSubQuery(LogicalNode node) { this.subQuery = node; setInSchema(SchemaUtil.clone(this.subQuery.getOutSchema())); getInSchema().setQualifier(this.tableName); if (hasTargets()) { setOutSchema(PlannerUtil.targetToSchema(targets)); } else { setOutSchema(SchemaUtil.clone(this.subQuery.getOutSchema())); } }
public void setSubQuery(LogicalNode node) { this.subQuery = node; setInSchema(SchemaUtil.clone(this.subQuery.getOutSchema())); getInSchema().setQualifier(this.tableName); if (hasTargets()) { setOutSchema(PlannerUtil.targetToSchema(targets)); } else { setOutSchema(SchemaUtil.clone(this.subQuery.getOutSchema())); } }
if (copy.getInSchema().containsAll(copy.getOutSchema().getRootColumns())) { for (Target eachTarget : copy.getTargets()) { Set<Column> columns = EvalTreeUtil.findUniqueColumns(eachTarget.getEvalTree()); if (copy.getInSchema().containsAll(columns)) { leftMostSubQueryNode = copy; break; throw new TajoInternalError("Target of a UnionNode's subquery should be FieldEval."); int index = leftMostSubQueryNode.getInSchema().getColumnId(targets[i].getNamedColumn().getQualifiedName()); if (index < 0) { index = leftMostSubQueryNode.getInSchema().getColumnId(column.getQualifiedName()); + "->" + leftMostSubQueryNode.getInSchema()); Column inColumn = eachNode.getInSchema().getColumn(targetMappings[i]); eachNodeTargets[i].setAlias(eachNodeTargets[i].getNamedColumn().getQualifiedName()); EvalNode evalNode = eachNodeTargets[i].getEvalTree();
@Override public LogicalNode visitTableSubQuery(ProcessorContext ctx, Stack<Expr> stack, TablePrimarySubQuery expr) throws TajoException { QueryBlock childBlock = ctx.planContext.getPlan().getBlock( ctx.planContext.getPlan().getBlockNameByExpr(expr.getSubQuery())); ProcessorContext newContext = new ProcessorContext(new PlanContext(ctx.planContext, childBlock)); super.visitTableSubQuery(newContext, stack, expr); TableSubQueryNode node = getNodeFromExpr(ctx.planContext.getPlan(), expr); LogicalNode child = getNonRelationListExpr(ctx.planContext.getPlan(), expr.getSubQuery()); node.setInSchema(child.getOutSchema()); node.setOutSchema(node.getInSchema()); return node; }
@Override public LogicalNode visitSimpleTableSubquery(ProcessorContext ctx, Stack<Expr> stack, SimpleTableSubquery expr) throws TajoException { QueryBlock childBlock = ctx.planContext.getPlan().getBlock( ctx.planContext.getPlan().getBlockNameByExpr(expr.getSubQuery())); ProcessorContext newContext = new ProcessorContext(new PlanContext(ctx.planContext, childBlock)); super.visitSimpleTableSubquery(newContext, stack, expr); TableSubQueryNode node = getNodeFromExpr(ctx.planContext.getPlan(), expr); LogicalNode child = getNonRelationListExpr(ctx.planContext.getPlan(), expr.getSubQuery()); node.setInSchema(child.getOutSchema()); node.setOutSchema(node.getInSchema()); return node; }
@Override public LogicalNode visitTableSubQuery(ProcessorContext ctx, Stack<Expr> stack, TablePrimarySubQuery expr) throws TajoException { QueryBlock childBlock = ctx.planContext.getPlan().getBlock( ctx.planContext.getPlan().getBlockNameByExpr(expr.getSubQuery())); ProcessorContext newContext = new ProcessorContext(new PlanContext(ctx.planContext, childBlock)); super.visitTableSubQuery(newContext, stack, expr); TableSubQueryNode node = getNodeFromExpr(ctx.planContext.getPlan(), expr); LogicalNode child = getNonRelationListExpr(ctx.planContext.getPlan(), expr.getSubQuery()); node.setInSchema(child.getOutSchema()); node.setOutSchema(node.getInSchema()); return node; }
@Override public LogicalNode visitSimpleTableSubquery(ProcessorContext ctx, Stack<Expr> stack, SimpleTableSubquery expr) throws TajoException { QueryBlock childBlock = ctx.planContext.getPlan().getBlock( ctx.planContext.getPlan().getBlockNameByExpr(expr.getSubQuery())); ProcessorContext newContext = new ProcessorContext(new PlanContext(ctx.planContext, childBlock)); super.visitSimpleTableSubquery(newContext, stack, expr); TableSubQueryNode node = getNodeFromExpr(ctx.planContext.getPlan(), expr); LogicalNode child = getNonRelationListExpr(ctx.planContext.getPlan(), expr.getSubQuery()); node.setInSchema(child.getOutSchema()); node.setOutSchema(node.getInSchema()); 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; }