public void setRoot(LogicalNode blockRoot) { this.rootNode = blockRoot; if (blockRoot instanceof LogicalRootNode) { LogicalRootNode rootNode = (LogicalRootNode) blockRoot; rootType = rootNode.getChild().getType(); } }
@Override public LogicalNode visit(PlanShapeFixerContext context, LogicalPlan plan, LogicalPlan.QueryBlock block, LogicalNode node, Stack<LogicalNode> stack) throws TajoException { super.visit(context, plan, block, node, stack); node.setInSchema(sortSchema(node.getInSchema())); node.setOutSchema(sortSchema(node.getOutSchema())); context.childNumbers.push(context.childNumbers.pop() + 1); return null; }
public boolean deepEquals(Object o) { if (o instanceof BinaryNode) { BinaryNode b = (BinaryNode) o; return equals(o) && leftChild.deepEquals(b.leftChild) && rightChild.deepEquals(b.rightChild); } return false; }
private int [] registerGetChildIds(SerializeContext context, LogicalNode node) { int [] childIds = new int[node.childNum()]; for (int i = 0; i < node.childNum(); i++) { if (node.getChild(i) != null && context.idMap.containsKey(node.getChild(i).getPID())) { childIds[i] = context.idMap.get(node.getChild(i).getPID()); } else { childIds[i] = context.seqId++; } } return childIds; } }
private static PlanProto.LogicalNode.Builder createNodeBuilder(SerializeContext context, LogicalNode node) { int selfId; if (context.idMap.containsKey(node.getPID())) { selfId = context.idMap.get(node.getPID()); } else { selfId = context.seqId++; context.idMap.put(node.getPID(), selfId); } PlanProto.LogicalNode.Builder nodeBuilder = PlanProto.LogicalNode.newBuilder(); nodeBuilder.setVisitSeq(selfId); nodeBuilder.setNodeId(node.getPID()); nodeBuilder.setType(convertType(node.getType())); // some DDL statements like DropTable or DropDatabase do not have in/out schemas if (node.getInSchema() != null) { nodeBuilder.setInSchema(node.getInSchema().getProto()); } if (node.getOutSchema() != null) { nodeBuilder.setOutSchema(node.getOutSchema().getProto()); } return nodeBuilder; }
if (unaryNode.getChild().deepEquals(target)) { unaryNode.setChild(tobeReplaced); left = tobeReplaced; if (binaryNode.getLeftChild().deepEquals(target)) { binaryNode.setLeftChild(tobeReplaced); left = tobeReplaced; if (binaryNode.getRightChild().deepEquals(target)) { binaryNode.setRightChild(tobeReplaced); right = tobeReplaced; if (node instanceof Projectable) { if (node instanceof BinaryNode) { node.setInSchema(SchemaUtil.merge(left.getOutSchema(), right.getOutSchema())); } else { node.setInSchema(left.getOutSchema()); node.setInSchema(left.getOutSchema()); node.setOutSchema(left.getOutSchema());
@Override public LogicalNode visitCreateIndex(LogicalPlanner.PlanContext ctx, Stack<Expr> stack, CreateIndex expr) throws TajoException { stack.push(expr); LogicalNode child = visit(ctx, stack, expr.getChild()); stack.pop(); CreateIndexNode createIndex = ctx.getPlan().createNode(CreateIndexNode.class); createIndex.setInSchema(child.getOutSchema()); createIndex.setOutSchema(child.getOutSchema()); return createIndex; }
/** * Check if CTAS is already done * @param rootNode * @return */ private boolean checkIfCtasAlreadyDone(LogicalNode rootNode) { if (rootNode.getChild(0).getType() == NodeType.CREATE_TABLE) { CreateTableNode createTable = (CreateTableNode) rootNode.getChild(0); if (createTable.isIfNotExists() && catalog.existsTable(createTable.getTableName())) { return true; } } return false; }
@Test public final void testVisitor() throws TajoException { QueryContext qc = createQueryContext(); // two relations Expr expr = sqlAnalyzer.parse(QUERIES[1]); LogicalNode plan = planner.createPlan(qc, expr).getRootBlock().getRoot(); TestVisitor vis = new TestVisitor(); plan.postOrder(vis); assertEquals(NodeType.ROOT, vis.stack.pop().getType()); assertEquals(NodeType.PROJECTION, vis.stack.pop().getType()); assertEquals(NodeType.JOIN, vis.stack.pop().getType()); assertEquals(NodeType.SCAN, vis.stack.pop().getType()); assertEquals(NodeType.SCAN, vis.stack.pop().getType()); }
/** * Try to find the column from the current node and child node. It can find subexprs generated from the optimizer. * * @param block The current query block * @param columnRef The column reference to be found * @return The found column */ static Column resolveFromCurrentAndChildNode(LogicalPlan.QueryBlock block, ColumnReferenceExpr columnRef) throws UndefinedColumnException { if (block.getCurrentNode() != null && block.getCurrentNode().getInSchema() != null) { Column found = block.getCurrentNode().getInSchema().getColumn(columnRef.getCanonicalName()); if (found != null) { return found; } else if (block.getLatestNode() != null) { found = block.getLatestNode().getOutSchema().getColumn(columnRef.getName()); if (found != null) { return found; } } } return null; }
@Override public LogicalNode visitFilter(GlobalPlanContext context, LogicalPlan plan, LogicalPlan.QueryBlock block, SelectionNode node, Stack<LogicalNode> stack) throws TajoException { LogicalNode child = super.visitFilter(context, plan, block, node, stack); ExecutionBlock execBlock = context.execBlockMap.remove(child.getPID()); node.setChild(execBlock.getPlan()); node.setInSchema(execBlock.getPlan().getOutSchema()); execBlock.setPlan(node); context.execBlockMap.put(node.getPID(), execBlock); return node; }
currentNodeSchema = ((RelationNode) currentNode).getLogicalSchema(); } else { currentNodeSchema = currentNode.getInSchema(); && currentNode.getType() != NodeType.TABLE_SUBQUERY) { List<Column> candidates = TUtil.newList(); if (block.getNamedExprsManager().isAliased(qualifiedName)) {
@Override public boolean equals(Object obj) { if (obj instanceof AlterTableNode) { AlterTableNode other = (AlterTableNode) obj; return super.equals(other); } else { return false; } }
@Override public Object clone() throws CloneNotSupportedException { CreateDatabaseNode newNode = (CreateDatabaseNode) super.clone(); newNode.databaseName = databaseName; newNode.ifNotExists = ifNotExists; return newNode; }
public static final void testCloneLogicalNode(LogicalNode n1) throws CloneNotSupportedException { LogicalNode copy = (LogicalNode) n1.clone(); assertTrue(n1.deepEquals(copy)); }
public static VerificationState verify(VerificationState state, LogicalNode currentNode, EvalNode expression) { instance.visit(state, expression, new Stack<EvalNode>()); Set<Column> referredColumns = EvalTreeUtil.findUniqueColumns(expression); for (Column referredColumn : referredColumns) { if (!currentNode.getInSchema().contains(referredColumn)) { throw new TajoInternalError("Invalid State: " + referredColumn + " cannot be accessible at Node (" + currentNode.getPID() + ")"); } } return state; }
@Override public LogicalNode visitGroupBy(GlobalPlanContext context, LogicalPlan plan, LogicalPlan.QueryBlock block, GroupbyNode node, Stack<LogicalNode> stack) throws TajoException { LogicalNode child = super.visitGroupBy(context, plan, block, node, stack); ExecutionBlock childBlock = context.execBlockMap.remove(child.getPID()); ExecutionBlock newExecBlock = buildGroupBy(context, childBlock, node); context.execBlockMap.put(newExecBlock.getPlan().getPID(), newExecBlock); return newExecBlock.getPlan(); }