/** * Add the supplied node to the end of the list of children. * * @param child the node that should be added as the last child; may not be null */ public void addLastChild( PlanNode child ) { assert child != null; this.children.addLast(child); child.removeFromParent(); child.parent = this; }
/** * Add the supplied node to the front of the list of children. * * @param child the node that should be added as the first child; may not be null */ public void addFirstChild( PlanNode child ) { assert child != null; this.children.addFirst(child); child.removeFromParent(); child.parent = this; }
/** * Add the supplied node to the end of the list of children. * * @param child the node that should be added as the last child; may not be null */ public void addLastChild( PlanNode child ) { assert child != null; this.children.addLast(child); child.removeFromParent(); child.parent = this; }
/** * Add the supplied node to the front of the list of children. * * @param child the node that should be added as the first child; may not be null */ public void addFirstChild( PlanNode child ) { assert child != null; this.children.addFirst(child); child.removeFromParent(); child.parent = this; }
/** * Set the parent for this node. If this node already has a parent, this method will remove this node from the current parent. * If the supplied parent is not null, then this node will be added to the supplied parent's children. * * @param parent the new parent, or null if this node is to have no parent */ public void setParent( PlanNode parent ) { removeFromParent(); if (parent != null) { this.parent = parent; this.parent.children.add(this); } }
/** * Set the parent for this node. If this node already has a parent, this method will remove this node from the current parent. * If the supplied parent is not null, then this node will be added to the supplied parent's children. * * @param parent the new parent, or null if this node is to have no parent */ public void setParent( PlanNode parent ) { removeFromParent(); if (parent != null) { this.parent = parent; this.parent.children.add(this); } }
/** * Replace the supplied child with another node. If the replacement is already a child of this node, this method effectively * swaps the position of the child and replacement nodes. * * @param child the node that is already a child and that is to be replaced; may not be null and must be a child * @param replacement the node that is to replace the 'child' node; may not be null * @return true if the child was successfully replaced */ public boolean replaceChild( PlanNode child, PlanNode replacement ) { assert child != null; assert replacement != null; if (child.parent == this) { int i = this.children.indexOf(child); if (replacement.parent == this) { // Swapping the positions ... int j = this.children.indexOf(replacement); this.children.set(i, replacement); this.children.set(j, child); return true; } // The replacement is not yet a child ... this.children.set(i, replacement); replacement.removeFromParent(); replacement.parent = this; child.parent = null; return true; } return false; }
/** * Replace the supplied child with another node. If the replacement is already a child of this node, this method effectively * swaps the position of the child and replacement nodes. * * @param child the node that is already a child and that is to be replaced; may not be null and must be a child * @param replacement the node that is to replace the 'child' node; may not be null * @return true if the child was successfully replaced */ public boolean replaceChild( PlanNode child, PlanNode replacement ) { assert child != null; assert replacement != null; if (child.parent == this) { int i = this.children.indexOf(child); if (replacement.parent == this) { // Swapping the positions ... int j = this.children.indexOf(replacement); this.children.set(i, replacement); this.children.set(j, child); return true; } // The replacement is not yet a child ... this.children.set(i, replacement); replacement.removeFromParent(); replacement.parent = this; child.parent = null; return true; } return false; }
newParent.removeFromParent(); if (this.parent != null) { this.parent.replaceChild(this, newParent);
newParent.removeFromParent(); if (this.parent != null) { this.parent.replaceChild(this, newParent);
@Override public PlanNode execute( QueryContext context, PlanNode plan, LinkedList<OptimizerRule> ruleStack ) { // For each of the JOIN nodes ... for (PlanNode joinNode : plan.findAllAtOrBelow(Type.JOIN)) { if (JoinType.RIGHT_OUTER == joinNode.getProperty(Property.JOIN_TYPE, JoinType.class)) { // Swap the information ... PlanNode left = joinNode.getFirstChild(); left.removeFromParent(); // right is now the first child ... left.setParent(joinNode); joinNode.setProperty(Property.JOIN_TYPE, JoinType.LEFT_OUTER); // None of the Constraints or JoinCondition need to be changed (they refer to named selectors) ... } } return plan; }
@Override public PlanNode execute( QueryContext context, PlanNode plan, LinkedList<OptimizerRule> ruleStack ) { // For each of the JOIN nodes ... for (PlanNode joinNode : plan.findAllAtOrBelow(Type.JOIN)) { if (JoinType.RIGHT_OUTER == joinNode.getProperty(Property.JOIN_TYPE, JoinType.class)) { // Swap the information ... PlanNode left = joinNode.getFirstChild(); left.removeFromParent(); // right is now the first child ... left.setParent(joinNode); joinNode.setProperty(Property.JOIN_TYPE, JoinType.LEFT_OUTER); // None of the Constraints or JoinCondition need to be changed (they refer to named selectors) ... } } return plan; }
@Test public void shouldRemoveFromParentWhenThereIsNoParent() { node = new PlanNode(Type.JOIN); PlanNode child1 = new PlanNode(Type.ACCESS, node); assertThat(node.getFirstChild(), is(sameInstance(child1))); assertThat(node.getChildCount(), is(1)); // Perform the removeFromParent ... assertThat(node.removeFromParent(), is(nullValue())); assertThat(node.getFirstChild(), is(sameInstance(child1))); assertThat(node.getChildCount(), is(1)); }
if (swapChildren) { PlanNode first = join.getFirstChild(); first.removeFromParent(); join.addLastChild(first); if (joinType == JoinType.LEFT_OUTER){
if (swapChildren) { PlanNode first = join.getFirstChild(); first.removeFromParent(); join.addLastChild(first); if (joinType == JoinType.LEFT_OUTER){
@Test public void shouldRemoveFromParentWhenThereIsAParent() { parent = new PlanNode(Type.JOIN); PlanNode child1 = new PlanNode(Type.ACCESS, parent); PlanNode child2 = new PlanNode(Type.DUP_REMOVE, parent); PlanNode child3 = new PlanNode(Type.GROUP, parent); PlanNode grandChild21 = new PlanNode(Type.LIMIT, child2); assertThat(parent.getFirstChild(), is(sameInstance(child1))); assertThat(parent.getChild(1), is(sameInstance(child2))); assertThat(parent.getLastChild(), is(sameInstance(child3))); assertThat(parent.getChildCount(), is(3)); assertThat(child2.getFirstChild(), is(sameInstance(grandChild21))); // Perform the removeFromParent ... assertThat(child2.removeFromParent(), is(sameInstance(parent))); assertThat(parent.getFirstChild(), is(sameInstance(child1))); assertThat(parent.getLastChild(), is(sameInstance(child3))); assertThat(parent.getChildCount(), is(2)); // There should still be the child in the removed node ... assertThat(child2.getFirstChild(), is(sameInstance(grandChild21))); }
assert sort.getParent() == distinct; sort.removeFromParent(); assert sort.getParent() == null;
assert sort.getParent() == distinct; sort.removeFromParent(); assert sort.getParent() == null;
access.removeFromParent(); } else { project.extractFromParent();
access.removeFromParent(); } else { project.extractFromParent();