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; }
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; }
@Override public MasterPlan rewrite(OverridableConf queryContext, MasterPlan plan) { try { ExecutionBlockCursor cursor = new ExecutionBlockCursor(plan); for (ExecutionBlock eb : cursor) { LogicalNode node = eb.getPlan(); if (node != null) { PlanProto.LogicalNodeTree tree = LogicalNodeSerializer.serialize(node); LogicalNode deserialize = LogicalNodeDeserializer.deserialize(plan.getContext(), null, tree); assert node.deepEquals(deserialize); } } return plan; } catch (Throwable t) { throw new RuntimeException(t); } } }
@Override public MasterPlan rewrite(MasterPlan plan) { try { ExecutionBlockCursor cursor = new ExecutionBlockCursor(plan); for (ExecutionBlock eb : cursor) { LogicalNode node = eb.getPlan(); if (node != null) { PlanProto.LogicalNodeTree tree = LogicalNodeSerializer.serialize(node); LogicalNode deserialize = LogicalNodeDeserializer.deserialize(plan.getContext(), null, tree); assert node.deepEquals(deserialize); } } return plan; } catch (Throwable t) { throw new RuntimeException(t); } } }
public static final void testCloneLogicalNode(LogicalNode n1) throws CloneNotSupportedException { LogicalNode copy = (LogicalNode) n1.clone(); assertTrue(n1.deepEquals(copy)); }
/** * 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; }
@Override public LogicalPlan rewrite(LogicalPlanRewriteRuleContext context) throws TajoException { LogicalPlan plan = context.getPlan(); LogicalNode root = plan.getRootBlock().getRoot(); PlanProto.LogicalNodeTree serialized = LogicalNodeSerializer.serialize(plan.getRootBlock().getRoot()); LogicalNode deserialized = LogicalNodeDeserializer.deserialize(context.getQueryContext(), null, serialized); assert root.deepEquals(deserialized); return plan; } }
@Override public LogicalPlan rewrite(LogicalPlanRewriteRuleContext context) throws TajoException { LogicalPlan plan = context.getPlan(); LogicalNode root = plan.getRootBlock().getRoot(); PlanProto.LogicalNodeTree serialized = LogicalNodeSerializer.serialize(plan.getRootBlock().getRoot()); LogicalNode deserialized = LogicalNodeDeserializer.deserialize(context.getQueryContext(), null, serialized); assert root.deepEquals(deserialized); return plan; } }
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 (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;