@Override public Object visitScan(OverridableConf queryContext, LogicalPlan plan, LogicalPlan.QueryBlock block, ScanNode scanNode, Stack<LogicalNode> stack) throws TajoException { TableDesc table = scanNode.getTableDesc(); if (!table.hasPartition()) { return null; } try { Path [] filteredPaths = findFilteredPartitionPaths(queryContext, scanNode); plan.addHistory("PartitionTableRewriter chooses " + filteredPaths.length + " of partitions"); PartitionedTableScanNode rewrittenScanNode = plan.createNode(PartitionedTableScanNode.class); rewrittenScanNode.init(scanNode, filteredPaths); updateTableStat(queryContext, rewrittenScanNode); // if it is topmost node, set it as the rootnode of this block. if (stack.empty() || block.getRoot().equals(scanNode)) { block.setRoot(rewrittenScanNode); } else { PlannerUtil.replaceNode(plan, stack.peek(), scanNode, rewrittenScanNode); } block.registerNode(rewrittenScanNode); } catch (IOException e) { throw new TajoInternalError("Partitioned Table Rewrite Failed: \n" + e.getMessage()); } return null; } }
@Override public Object visitScan(OverridableConf queryContext, LogicalPlan plan, LogicalPlan.QueryBlock block, ScanNode scanNode, Stack<LogicalNode> stack) throws TajoException { TableDesc table = scanNode.getTableDesc(); if (!table.hasPartition()) { return null; } try { Path [] filteredPaths = findFilteredPartitionPaths(queryContext, scanNode); plan.addHistory("PartitionTableRewriter chooses " + filteredPaths.length + " of partitions"); PartitionedTableScanNode rewrittenScanNode = plan.createNode(PartitionedTableScanNode.class); rewrittenScanNode.init(scanNode, filteredPaths); rewrittenScanNode.getTableDesc().getStats().setNumBytes(totalVolume); // if it is topmost node, set it as the rootnode of this block. if (stack.empty() || block.getRoot().equals(scanNode)) { block.setRoot(rewrittenScanNode); } else { PlannerUtil.replaceNode(plan, stack.peek(), scanNode, rewrittenScanNode); } block.registerNode(rewrittenScanNode); } catch (IOException e) { throw new TajoInternalError("Partitioned Table Rewrite Failed: \n" + e.getMessage()); } return null; } }
private SelectionNode createSelectionParentForNonEquiThetaJoinQuals(LogicalPlan plan, QueryBlock block, Stack<LogicalNode> stack, JoinNode joinNode, List<EvalNode> nonEquiThetaJoinQuals) { SelectionNode selectionNode = plan.createNode(SelectionNode.class); selectionNode.setInSchema(joinNode.getOutSchema()); selectionNode.setOutSchema(joinNode.getOutSchema()); selectionNode.setQual(AlgebraicUtil.createSingletonExprFromCNF(nonEquiThetaJoinQuals)); block.registerNode(selectionNode); LogicalNode parent = stack.peek(); if (parent instanceof UnaryNode) { ((UnaryNode) parent).setChild(selectionNode); } else if (parent instanceof BinaryNode) { BinaryNode binaryParent = (BinaryNode) parent; if (binaryParent.getLeftChild().getPID() == joinNode.getPID()) { binaryParent.setLeftChild(selectionNode); } else if (binaryParent.getRightChild().getPID() == joinNode.getPID()) { binaryParent.setRightChild(selectionNode); } } else if (parent instanceof TableSubQueryNode) { ((TableSubQueryNode) parent).setSubQuery(selectionNode); } selectionNode.setChild(joinNode); return selectionNode; }
context.generateUniqueSubQueryName()), setOperationNode); setTargetOfTableSubQuery(context, currentBlock, setOpTableSubQueryNode); currentBlock.registerNode(setOpTableSubQueryNode); currentBlock.addRelation(setOpTableSubQueryNode); setOpGroupbyNode.setTargets(setOpTarget); setOpGroupbyNode.setChild(setOpTableSubQueryNode); currentBlock.registerNode(setOpGroupbyNode); setOpProjectionNode.setTargets(setOpTarget); setOpProjectionNode.setChild(setOpGroupbyNode); currentBlock.registerNode(setOpProjectionNode); setOpBlock.registerNode(setOperationNode); setOpBlock.setRoot(setOperationNode);
plan.getRootBlock().registerNode(sortNode);
plan.getRootBlock().registerNode(sortNode);
context.generateUniqueSubQueryName()), setOperationNode); setTargetOfTableSubQuery(context, currentBlock, setOpTableSubQueryNode); currentBlock.registerNode(setOpTableSubQueryNode); currentBlock.addRelation(setOpTableSubQueryNode); setOpGroupbyNode.setTargets(setOpTarget); setOpGroupbyNode.setChild(setOpTableSubQueryNode); currentBlock.registerNode(setOpGroupbyNode); setOpProjectionNode.setTargets(setOpTarget); setOpProjectionNode.setChild(setOpGroupbyNode); currentBlock.registerNode(setOpProjectionNode); setOpBlock.registerNode(setOperationNode); setOpBlock.setRoot(setOperationNode);
dupRemoval.setGroupingColumns(sortNode.getInSchema().toArray()); block.registerNode(dupRemoval); postHook(context, stack, null, dupRemoval); dupRemoval.setGroupingColumns(outSchema.toArray()); block.registerNode(dupRemoval); postHook(context, stack, null, dupRemoval);
@Override public LogicalNode buildPlan(LogicalPlan plan, LogicalPlan.QueryBlock block) { // TODO LogicalNode leftChild = joinEdge.getLeftVertex().buildPlan(plan, block); LogicalNode rightChild = joinEdge.getRightVertex().buildPlan(plan, block); JoinNode joinNode = plan.createNode(JoinNode.class); if (PlannerUtil.isCommutativeJoinType(joinEdge.getJoinType())) { // if only one operator is relation if ((leftChild instanceof RelationNode) && !(rightChild instanceof RelationNode)) { // for left deep joinNode.init(joinEdge.getJoinType(), rightChild, leftChild); } else { // if both operators are relation or if both are relations // we don't need to concern the left-right position. joinNode.init(joinEdge.getJoinType(), leftChild, rightChild); } } else { joinNode.init(joinEdge.getJoinType(), leftChild, rightChild); } Schema mergedSchema = SchemaUtil.merge(joinNode.getLeftChild().getOutSchema(), joinNode.getRightChild().getOutSchema()); joinNode.setInSchema(mergedSchema); joinNode.setOutSchema(mergedSchema); if (joinEdge.hasJoinQual()) { joinNode.setJoinQual(joinEdge.getSingletonJoinQual()); } block.registerNode(joinNode); return joinNode; }
@Override public LogicalNode buildPlan(LogicalPlan plan, LogicalPlan.QueryBlock block) { // TODO LogicalNode leftChild = joinEdge.getLeftVertex().buildPlan(plan, block); LogicalNode rightChild = joinEdge.getRightVertex().buildPlan(plan, block); JoinNode joinNode = plan.createNode(JoinNode.class); if (PlannerUtil.isCommutativeJoinType(joinEdge.getJoinType())) { // if only one operator is relation if ((leftChild instanceof RelationNode) && !(rightChild instanceof RelationNode)) { // for left deep joinNode.init(joinEdge.getJoinType(), rightChild, leftChild); } else { // if both operators are relation or if both are relations // we don't need to concern the left-right position. joinNode.init(joinEdge.getJoinType(), leftChild, rightChild); } } else { joinNode.init(joinEdge.getJoinType(), leftChild, rightChild); } Schema mergedSchema = SchemaUtil.merge(joinNode.getLeftChild().getOutSchema(), joinNode.getRightChild().getOutSchema()); joinNode.setInSchema(mergedSchema); joinNode.setOutSchema(mergedSchema); if (joinEdge.hasJoinQual()) { joinNode.setJoinQual(joinEdge.getSingletonJoinQual()); } block.registerNode(joinNode); return joinNode; }
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; }
dupRemoval.setGroupingColumns(sortNode.getInSchema().toArray()); block.registerNode(dupRemoval); postHook(context, stack, null, dupRemoval); dupRemoval.setGroupingColumns(outSchema.toArray()); block.registerNode(dupRemoval); postHook(context, stack, null, dupRemoval);
private SelectionNode createSelectionParentForNonEquiThetaJoinQuals(LogicalPlan plan, QueryBlock block, Stack<LogicalNode> stack, JoinNode joinNode, List<EvalNode> nonEquiThetaJoinQuals) { SelectionNode selectionNode = plan.createNode(SelectionNode.class); selectionNode.setInSchema(joinNode.getOutSchema()); selectionNode.setOutSchema(joinNode.getOutSchema()); selectionNode.setQual(AlgebraicUtil.createSingletonExprFromCNF(nonEquiThetaJoinQuals)); block.registerNode(selectionNode); LogicalNode parent = stack.peek(); if (parent instanceof UnaryNode) { ((UnaryNode) parent).setChild(selectionNode); } else if (parent instanceof BinaryNode) { BinaryNode binaryParent = (BinaryNode) parent; if (binaryParent.getLeftChild().getPID() == joinNode.getPID()) { binaryParent.setLeftChild(selectionNode); } else if (binaryParent.getRightChild().getPID() == joinNode.getPID()) { binaryParent.setRightChild(selectionNode); } } else if (parent instanceof TableSubQueryNode) { ((TableSubQueryNode) parent).setSubQuery(selectionNode); } selectionNode.setChild(joinNode); return selectionNode; }
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; }
@Override public LogicalNode visitRelationList(PlanContext context, Stack<Expr> stack, RelationList relations) throws TajoException { LogicalNode current = visit(context, stack, relations.getRelations()[0]); LogicalNode left; LogicalNode right; if (relations.size() > 1) { for (int i = 1; i < relations.size(); i++) { left = current; right = visit(context, stack, relations.getRelations()[i]); current = createCartesianProduct(context, left, right); } } context.queryBlock.registerNode(current); return current; }
private void insertDistinctOperator(LogicalPlan plan, LogicalPlan.QueryBlock block, ProjectionNode projectionNode, LogicalNode child) throws TajoException { if (projectionNode.getChild().getType() != NodeType.GROUP_BY) { Schema outSchema = projectionNode.getOutSchema(); GroupbyNode dupRemoval = plan.createNode(GroupbyNode.class); dupRemoval.setChild(child); dupRemoval.setInSchema(projectionNode.getInSchema()); dupRemoval.setTargets(PlannerUtil.schemaToTargets(outSchema)); dupRemoval.setGroupingColumns(outSchema.toArray()); block.registerNode(dupRemoval); block.setAggregationRequire(); projectionNode.setChild(dupRemoval); projectionNode.setInSchema(dupRemoval.getOutSchema()); } }
private void insertDistinctOperator(LogicalPlan plan, LogicalPlan.QueryBlock block, ProjectionNode projectionNode, LogicalNode child) throws TajoException { if (projectionNode.getChild().getType() != NodeType.GROUP_BY) { Schema outSchema = projectionNode.getOutSchema(); GroupbyNode dupRemoval = plan.createNode(GroupbyNode.class); dupRemoval.setChild(child); dupRemoval.setInSchema(projectionNode.getInSchema()); dupRemoval.setTargets(PlannerUtil.schemaToTargets(outSchema)); dupRemoval.setGroupingColumns(outSchema.toArray()); block.registerNode(dupRemoval); block.setAggregationRequire(); projectionNode.setChild(dupRemoval); projectionNode.setInSchema(dupRemoval.getOutSchema()); } }
@Override public LogicalNode visitRelationList(PlanContext context, Stack<Expr> stack, RelationList relations) throws TajoException { LogicalNode current = visit(context, stack, relations.getRelations()[0]); LogicalNode left; LogicalNode right; if (relations.size() > 1) { for (int i = 1; i < relations.size(); i++) { left = current; right = visit(context, stack, relations.getRelations()[i]); current = createCartesianProduct(context, left, right); } } context.queryBlock.registerNode(current); return current; }
@Override public LogicalNode postHook(LogicalPlanner.PlanContext ctx, Stack<Expr> stack, Expr expr, LogicalNode result) throws TajoException { // If non-from statement, result can be null. It avoids that case. if (result != null) { // setNode method registers each node to corresponding block and plan. ctx.getQueryBlock().registerNode(result); // It makes a map between an expr and a logical node. ctx.getQueryBlock().registerExprWithNode(expr, result); } return result; }
@Override public LogicalNode postHook(LogicalPlanner.PlanContext ctx, Stack<Expr> stack, Expr expr, LogicalNode result) throws TajoException { // If non-from statement, result can be null. It avoids that case. if (result != null) { // setNode method registers each node to corresponding block and plan. ctx.getQueryBlock().registerNode(result); // It makes a map between an expr and a logical node. ctx.getQueryBlock().registerExprWithNode(expr, result); } return result; }