RightOuterToLeftOuterJoins implements OptimizerRule { @Override public PlanNode execute( QueryContext context, PlanNode plan, LinkedList<OptimizerRule> ruleStack ) { for (PlanNode joinNode : plan.findAllAtOrBelow(Type.JOIN)) { if (JoinType.RIGHT_OUTER == joinNode.getProperty(Property.JOIN_TYPE, JoinType.class)) { PlanNode left = joinNode.getFirstChild(); left.removeFromParent(); left.setParent(joinNode); joinNode.setProperty(Property.JOIN_TYPE, JoinType.LEFT_OUTER); } } return plan; }  @Override PlanNode execute( QueryContext context,
                             PlanNode plan,
                             LinkedList<OptimizerRule> ruleStack ); @Override String toString(); static final RightOuterToLeftOuterJoins INSTANCE; }
@Test public void shouldDoNothingWithLeftOuterJoin() { PlanNode joinNode = new PlanNode(Type.JOIN); joinNode.setProperty(Property.JOIN_TYPE, JoinType.LEFT_OUTER); PlanNode lhs = new PlanNode(Type.SOURCE, joinNode); PlanNode rhs = new PlanNode(Type.SOURCE, joinNode); PlanNode result = rule.execute(context, joinNode, new LinkedList<OptimizerRule>()); assertThat(result, is(sameInstance(joinNode))); assertThat(joinNode.getProperty(Property.JOIN_TYPE, JoinType.class), is(JoinType.LEFT_OUTER)); assertThat(joinNode.getFirstChild(), is(sameInstance(lhs))); assertThat(joinNode.getLastChild(), is(sameInstance(rhs))); assertThat(joinNode.getChildCount(), is(2)); }
@Test public void shouldDoNothingWithCrossJoin() { PlanNode joinNode = new PlanNode(Type.JOIN); joinNode.setProperty(Property.JOIN_TYPE, JoinType.CROSS); PlanNode lhs = new PlanNode(Type.SOURCE, joinNode); PlanNode rhs = new PlanNode(Type.SOURCE, joinNode); PlanNode result = rule.execute(context, joinNode, new LinkedList<OptimizerRule>()); assertThat(result, is(sameInstance(joinNode))); assertThat(joinNode.getProperty(Property.JOIN_TYPE, JoinType.class), is(JoinType.CROSS)); assertThat(joinNode.getFirstChild(), is(sameInstance(lhs))); assertThat(joinNode.getLastChild(), is(sameInstance(rhs))); assertThat(joinNode.getChildCount(), is(2)); }
@Test public void shouldDoNothingWithFullOuterJoin() { PlanNode joinNode = new PlanNode(Type.JOIN); joinNode.setProperty(Property.JOIN_TYPE, JoinType.FULL_OUTER); PlanNode lhs = new PlanNode(Type.SOURCE, joinNode); PlanNode rhs = new PlanNode(Type.SOURCE, joinNode); PlanNode result = rule.execute(context, joinNode, new LinkedList<OptimizerRule>()); assertThat(result, is(sameInstance(joinNode))); assertThat(joinNode.getProperty(Property.JOIN_TYPE, JoinType.class), is(JoinType.FULL_OUTER)); assertThat(joinNode.getFirstChild(), is(sameInstance(lhs))); assertThat(joinNode.getLastChild(), is(sameInstance(rhs))); assertThat(joinNode.getChildCount(), is(2)); }
@Test public void shouldDoNothingWithInnerJoin() { PlanNode joinNode = new PlanNode(Type.JOIN); joinNode.setProperty(Property.JOIN_TYPE, JoinType.INNER); PlanNode lhs = new PlanNode(Type.SOURCE, joinNode); PlanNode rhs = new PlanNode(Type.SOURCE, joinNode); PlanNode result = rule.execute(context, joinNode, new LinkedList<OptimizerRule>()); assertThat(result, is(sameInstance(joinNode))); assertThat(joinNode.getProperty(Property.JOIN_TYPE, JoinType.class), is(JoinType.INNER)); assertThat(joinNode.getFirstChild(), is(sameInstance(lhs))); assertThat(joinNode.getLastChild(), is(sameInstance(rhs))); assertThat(joinNode.getChildCount(), is(2)); }
@Test public void shouldChangeRightOuterJoinToLeftOuterJoinAndReverseChildNodes() { PlanNode joinNode = new PlanNode(Type.JOIN); joinNode.setProperty(Property.JOIN_TYPE, JoinType.RIGHT_OUTER); PlanNode lhs = new PlanNode(Type.SOURCE, joinNode); PlanNode rhs = new PlanNode(Type.SOURCE, joinNode); PlanNode result = rule.execute(context, joinNode, new LinkedList<OptimizerRule>()); assertThat(result, is(sameInstance(joinNode))); assertThat(joinNode.getProperty(Property.JOIN_TYPE, JoinType.class), is(JoinType.LEFT_OUTER)); assertThat(joinNode.getFirstChild(), is(sameInstance(rhs))); assertThat(joinNode.getLastChild(), is(sameInstance(lhs))); assertThat(joinNode.getChildCount(), is(2)); }