}
@Test
public void shouldNotAddJoinConditionColumnIfAlreadyUsed() {
// Create a join ...
PlanNode joinNode = new PlanNode(Type.JOIN);
joinNode.setProperty(Property.JOIN_TYPE, JoinType.LEFT_OUTER);
joinNode.setProperty(Property.JOIN_CONDITION, new EquiJoinCondition(selector("left"), "c2", selector("right"), "d2"));
PlanNode lhs = sourceNode(context, joinNode, "left", "c1", "c2", "c3");
PlanNode rhs = sourceNode(context, joinNode, "right", "d1", "d2", "d3");
// Execute the rule ...
PlanNode result = rule.execute(context, joinNode, new LinkedList<OptimizerRule>());
assertThat(result, is(sameInstance(joinNode)));
// Verify nothing has changed ...
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));
PlanNode left = joinNode.getFirstChild();
PlanNode right = joinNode.getLastChild();
assertProperty(left, Property.PROJECT_COLUMNS, columns(context, selector("left"), "c1", "c2", "c3"));
assertProperty(left, Property.PROJECT_COLUMN_TYPES, columnTypes(context, selector("left"), "c1", "c2", "c3"));
assertProperty(right, Property.PROJECT_COLUMNS, columns(context, selector("right"), "d1", "d2", "d3"));
assertProperty(right, Property.PROJECT_COLUMN_TYPES, columnTypes(context, selector("right"), "d1", "d2", "d3"));
}