public void setLogicalPlan(LogicalNode plan) { this.plan = plan; LogicalNode node = plan; ArrayList<LogicalNode> s = new ArrayList<LogicalNode>(); s.add(node); while (!s.isEmpty()) { node = s.remove(s.size()-1); if (node instanceof UnaryNode) { UnaryNode unary = (UnaryNode) node; s.add(s.size(), unary.getChild()); } else if (node instanceof BinaryNode) { BinaryNode binary = (BinaryNode) node; s.add(s.size(), binary.getLeftChild()); s.add(s.size(), binary.getRightChild()); } else if (node instanceof ScanNode) { scan.add((ScanNode)node); } else if (node instanceof TableSubQueryNode) { s.add(((TableSubQueryNode) node).getSubQuery()); } } }
public void setLogicalPlan(LogicalNode plan) { this.plan = plan; LogicalNode node = plan; ArrayList<LogicalNode> s = new ArrayList<>(); s.add(node); while (!s.isEmpty()) { node = s.remove(s.size()-1); if (node instanceof UnaryNode) { UnaryNode unary = (UnaryNode) node; s.add(s.size(), unary.getChild()); } else if (node instanceof BinaryNode) { BinaryNode binary = (BinaryNode) node; s.add(s.size(), binary.getLeftChild()); s.add(s.size(), binary.getRightChild()); } else if (node instanceof ScanNode) { scan.add((ScanNode)node); } else if (node instanceof TableSubQueryNode) { s.add(((TableSubQueryNode) node).getSubQuery()); } } }
private LogicalNode visitBinaryNode(Context context, LogicalPlan plan, LogicalPlan.QueryBlock block, BinaryNode node, Stack<LogicalNode> stack) throws TajoException { context.depth++; stack.push(node); visit(context, plan, block, node.getLeftChild(), stack); visit(context, plan, block, node.getRightChild(), stack); stack.pop(); context.depth--; context.add(context.depth, node.getPlanString()); return node; }
private LogicalNode visitBinaryNode(Context context, LogicalPlan plan, LogicalPlan.QueryBlock block, BinaryNode node, Stack<LogicalNode> stack) throws TajoException { context.depth++; stack.push(node); visit(context, plan, block, node.getLeftChild(), stack); visit(context, plan, block, node.getRightChild(), stack); stack.pop(); context.depth--; context.add(context.depth, node.getPlanString()); return node; }
@Override public void visit(LogicalNode node) { if (node instanceof UnaryNode) { UnaryNode unary = (UnaryNode) node; if (unary.getChild().getType() == tofind) { list.add(node); } } else if (node instanceof BinaryNode) { BinaryNode bin = (BinaryNode) node; if (bin.getLeftChild().getType() == tofind || bin.getRightChild().getType() == tofind) { list.add(node); } } }
@Override public void visit(LogicalNode node) { if (node instanceof UnaryNode) { UnaryNode unary = (UnaryNode) node; if (unary.getChild().getType() == tofind) { list.add(node); } } else if (node instanceof BinaryNode) { BinaryNode bin = (BinaryNode) node; if (bin.getLeftChild().getType() == tofind || bin.getRightChild().getType() == tofind) { list.add(node); } } }
/** * Delete the logical node from a plan. * * @param parent this node must be a parent node of one node to be removed. * @param tobeRemoved this node must be a child node of the parent. */ public static LogicalNode deleteNode(LogicalNode parent, LogicalNode tobeRemoved) { Preconditions.checkArgument(tobeRemoved instanceof UnaryNode, "ERROR: the logical node to be removed must be unary node."); UnaryNode child = (UnaryNode) tobeRemoved; LogicalNode grandChild = child.getChild(); if (parent instanceof UnaryNode) { UnaryNode unaryParent = (UnaryNode) parent; Preconditions.checkArgument(unaryParent.getChild() == child, "ERROR: both logical node must be parent and child nodes"); unaryParent.setChild(grandChild); } else if (parent instanceof BinaryNode) { BinaryNode binaryParent = (BinaryNode) parent; if (binaryParent.getLeftChild().deepEquals(child)) { binaryParent.setLeftChild(grandChild); } else if (binaryParent.getRightChild().deepEquals(child)) { binaryParent.setRightChild(grandChild); } else { throw new TajoInternalError("both logical node must be parent and child nodes"); } } else { throw new TajoInternalError("unexpected logical plan: " + parent); } return child; }
/** * Delete the logical node from a plan. * * @param parent this node must be a parent node of one node to be removed. * @param tobeRemoved this node must be a child node of the parent. */ public static LogicalNode deleteNode(LogicalNode parent, LogicalNode tobeRemoved) { Preconditions.checkArgument(tobeRemoved instanceof UnaryNode, "ERROR: the logical node to be removed must be unary node."); UnaryNode child = (UnaryNode) tobeRemoved; LogicalNode grandChild = child.getChild(); if (parent instanceof UnaryNode) { UnaryNode unaryParent = (UnaryNode) parent; Preconditions.checkArgument(unaryParent.getChild() == child, "ERROR: both logical node must be parent and child nodes"); unaryParent.setChild(grandChild); } else if (parent instanceof BinaryNode) { BinaryNode binaryParent = (BinaryNode) parent; if (binaryParent.getLeftChild().deepEquals(child)) { binaryParent.setLeftChild(grandChild); } else if (binaryParent.getRightChild().deepEquals(child)) { binaryParent.setRightChild(grandChild); } else { throw new TajoInternalError("both logical node must be parent and child nodes"); } } else { throw new TajoInternalError("unexpected logical plan: " + parent); } return child; }
if (binaryNode.getLeftChild().deepEquals(target)) { binaryNode.setLeftChild(tobeReplaced); left = tobeReplaced; context.updateSchemaFlag = true; } else if (checkIfVisitable(binaryNode.getLeftChild())) { left = visit(context, plan, null, binaryNode.getLeftChild(), stack); } else { left = binaryNode.getLeftChild();
if (binaryNode.getLeftChild().deepEquals(target)) { binaryNode.setLeftChild(tobeReplaced); left = tobeReplaced; context.updateSchemaFlag = true; } else if (checkIfVisitable(binaryNode.getLeftChild())) { left = visit(context, plan, null, binaryNode.getLeftChild(), stack); } else { left = binaryNode.getLeftChild();
/** * Replace a child of the given parent logical node with the new one. * * @param newChild * @param originalChild * @param parent */ public static void replaceChild(LogicalNode newChild, ScanNode originalChild, LogicalNode parent) { if (parent instanceof UnaryNode) { ((UnaryNode) parent).setChild(newChild); } else if (parent instanceof BinaryNode) { BinaryNode binary = (BinaryNode) parent; if (binary.getLeftChild().equals(originalChild)) { binary.setLeftChild(newChild); } else if (binary.getRightChild().equals(originalChild)) { binary.setRightChild(newChild); } else { throw new TajoInternalError(originalChild.getPID() + " is not a child of " + parent.getPID()); } } else { throw new TajoInternalError(parent.getPID() + " seems to not have any children"); } }
/** * Replace a child of the given parent logical node with the new one. * * @param newChild * @param originalChild * @param parent */ public static void replaceChild(LogicalNode newChild, ScanNode originalChild, LogicalNode parent) { if (parent instanceof UnaryNode) { ((UnaryNode) parent).setChild(newChild); } else if (parent instanceof BinaryNode) { BinaryNode binary = (BinaryNode) parent; if (binary.getLeftChild().equals(originalChild)) { binary.setLeftChild(newChild); } else if (binary.getRightChild().equals(originalChild)) { binary.setRightChild(newChild); } else { throw new TajoInternalError(originalChild.getPID() + " is not a child of " + parent.getPID()); } } else { throw new TajoInternalError(parent.getPID() + " seems to not have any children"); } }
private void verifySetStatement(VerificationState state, BinaryNode setNode) { Preconditions.checkArgument(setNode.getType() == NodeType.UNION || setNode.getType() == NodeType.INTERSECT || setNode.getType() == NodeType.EXCEPT); Schema left = setNode.getLeftChild().getOutSchema(); Schema right = setNode.getRightChild().getOutSchema(); NodeType type = setNode.getType(); if (left.size() != right.size()) { state.addVerification(new TajoException(Errors.ResultCode.AMBIGUOUS_FUNCTION)); return; } Column[] leftColumns = left.toArray(); Column[] rightColumns = right.toArray(); for (int i = 0; i < leftColumns.length; i++) { if (!leftColumns[i].getDataType().equals(rightColumns[i].getDataType())) { state.addVerification( makeSetOpDataTypeMisMatch(type, leftColumns[i].getDataType(), rightColumns[i].getDataType()) ); } } }
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 void verifySetStatement(VerificationState state, BinaryNode setNode) { Preconditions.checkArgument(setNode.getType() == NodeType.UNION || setNode.getType() == NodeType.INTERSECT || setNode.getType() == NodeType.EXCEPT); Schema left = setNode.getLeftChild().getOutSchema(); Schema right = setNode.getRightChild().getOutSchema(); NodeType type = setNode.getType(); if (left.size() != right.size()) { state.addVerification(new TajoException(Errors.ResultCode.AMBIGUOUS_FUNCTION)); return; } Column[] leftColumns = left.toArray(); Column[] rightColumns = right.toArray(); for (int i = 0; i < leftColumns.length; i++) { if (!leftColumns[i].getDataType().equals(rightColumns[i].getDataType())) { state.addVerification( makeSetOpDataTypeMisMatch(type, leftColumns[i].getDataType(), rightColumns[i].getDataType()) ); } } }
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; }
} else if (node instanceof BinaryNode) { BinaryNode binaryNode = (BinaryNode) node; return computeDescendentVolume(binaryNode.getLeftChild()) + computeDescendentVolume(binaryNode.getRightChild());
} else if (node instanceof BinaryNode) { BinaryNode binaryNode = (BinaryNode) node; return computeDescendentVolume(binaryNode.getLeftChild()) + computeDescendentVolume(binaryNode.getRightChild());