/** * 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; }
setOp.setRightChild(rightChild);
setOp.setRightChild(rightChild);
/** * 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 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 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; }
binaryNode.setRightChild(tobeReplaced); right = tobeReplaced; context.updateSchemaFlag = true;
binaryNode.setRightChild(tobeReplaced); right = tobeReplaced; context.updateSchemaFlag = true;