Source:
private void convertJoin(Blackboard bb, SqlJoin join) { final SqlValidatorScope scope = validator.getJoinScope(join); final Blackboard fromBlackboard = createBlackboard(scope, null, false); SqlNode left = join.getLeft(); SqlNode right = join.getRight(); final SqlValidatorScope leftScope = Util.first(validator.getJoinScope(left), ((DelegatingScope) bb.scope).getParent()); final Blackboard leftBlackboard = createBlackboard(leftScope, null, false); final SqlValidatorScope rightScope = Util.first(validator.getJoinScope(right), ((DelegatingScope) bb.scope).getParent()); final Blackboard rightBlackboard = createBlackboard(rightScope, null, false); convertFrom(leftBlackboard, left); final RelNode leftRel = leftBlackboard.root; convertFrom(rightBlackboard, right); final RelNode tempRightRel = rightBlackboard.root; final JoinConditionType conditionType = join.getConditionType(); final RexNode condition; final RelNode rightRel; if (join.isNatural()) { condition = createNaturalJoinCondition(validator.getNamespace(left), validator.getNamespace(right)); rightRel = tempRightRel; } else if (conditionType == JoinConditionType.NONE) { condition = rexBuilder.makeLiteral(true); rightRel = tempRightRel; } else if (conditionType == JoinConditionType.USING) { condition = createJoinUsingCondition(join, validator.getNamespace(left), validator.getNamespace(right)); rightRel = tempRightRel; } else if (conditionType == JoinConditionType.ON) { Pair<RexNode, RelNode> conditionAndRightNode = createJoinOnCondition(fromBlackboard, join, leftRel, tempRightRel); condition = conditionAndRightNode.left; rightRel = conditionAndRightNode.right; } else { throw Util.unexpected(conditionType); } final RelNode joinRel = createJoin( fromBlackboard, leftRel, rightRel, condition, convertJoinType(join.getJoinType())); bb.setRoot(joinRel, false); }

Target:
private void convertJoin(Blackboard bb, SqlJoin join) { final SqlValidatorScope scope = validator.getJoinScope(join); final Blackboard fromBlackboard = createBlackboard(scope, null, false); SqlNode left = join.getLeft(); SqlNode right = join.getRight(); final SqlValidatorScope leftScope = Util.first(validator.getJoinScope(left), ((DelegatingScope) bb.scope).getParent()); final Blackboard leftBlackboard = createBlackboard(leftScope, null, false); final SqlValidatorScope rightScope = Util.first(validator.getJoinScope(right), ((DelegatingScope) bb.scope).getParent()); final Blackboard rightBlackboard = createBlackboard(rightScope, null, false); convertFrom(leftBlackboard, left); final RelNode leftRel = leftBlackboard.root; convertFrom(rightBlackboard, right); final RelNode tempRightRel = rightBlackboard.root; final JoinConditionType conditionType = join.getConditionType(); final RexNode condition; final RelNode rightRel; if (join.isNatural()) { condition = createNaturalJoinCondition(validator.getNamespace(left), validator.getNamespace(right)); rightRel = tempRightRel; } else { switch (conditionType) { case NONE: condition = rexBuilder.makeLiteral(true); rightRel = tempRightRel; break; case USING: condition = createJoinUsingCondition(join, validator.getNamespace(left), validator.getNamespace(right)); rightRel = tempRightRel; break; case ON: Pair<RexNode, RelNode> conditionAndRightNode = createJoinOnCondition(fromBlackboard, join, leftRel, tempRightRel); condition = conditionAndRightNode.left; rightRel = conditionAndRightNode.right; break; default: throw Util.unexpected(conditionType); } } final RelNode joinRel = createJoin( fromBlackboard, leftRel, rightRel, condition, convertJoinType(join.getJoinType())); bb.setRoot(joinRel, false); }