List<RexNode> joinConditions = new ArrayList<RexNode>();
// right fields appear after the LHS fields.
final int rightInputOffset = left.getRowType().getFieldCount();
for (JoinCondition condition : join.getConditions()) {
RelDataTypeField leftField = left.getRowType().getField(ExprHelper.getFieldName(condition.getLeft()), true);
RelDataTypeField rightField = right.getRowType().getField(ExprHelper.getFieldName(condition.getRight()), true);
joinConditions.add(
context.getRexBuilder().makeCall(
SqlStdOperatorTable.EQUALS,
context.getRexBuilder().makeInputRef(leftField.getType(), leftField.getIndex()),
context.getRexBuilder().makeInputRef(rightField.getType(), rightInputOffset + rightField.getIndex())
)
);
}
RexNode rexCondition = RexUtil.composeConjunction(context.getRexBuilder(), joinConditions, false);
DrillJoinRel joinRel = new DrillJoinRel(context.getCluster(), context.getLogicalTraits(), left, right, rexCondition, join.getJoinType());