Source:
<code>private static RexNode canonizeNode(RexBuilder rexBuilder, RexNode condition) { switch (condition.getKind()) { case AND: case OR: { RexCall call = (RexCall) condition; SortedMap<String, RexNode> newOperands = new TreeMap<>(); for (RexNode operand : call.operands) { operand = canonizeNode(rexBuilder, operand); newOperands.put(operand.toString(), operand); } if (newOperands.size() < 2) { return newOperands.values().iterator().next(); } return rexBuilder.makeCall(call.getOperator(), ImmutableList.copyOf(newOperands.values())); } case EQUALS: case NOT_EQUALS: case LESS_THAN: case GREATER_THAN: case LESS_THAN_OR_EQUAL: case GREATER_THAN_OR_EQUAL: { RexCall call = (RexCall) condition; <START> RexNode left = call.getOperands().get(0); <END> left = canonizeNode(rexBuilder, left); RexNode right = call.getOperands().get(1); right = canonizeNode(rexBuilder, right); call = (RexCall) rexBuilder.makeCall(call.getOperator(), left, right); if (left.toString().compareTo(right.toString()) <= 0) { return call; } return RexUtil.invert(rexBuilder, call); } case PLUS: case TIMES: RexCall call = (RexCall) condition; RexNode left = call.getOperands().get(0); RexNode right = call.getOperands().get(1); left = canonizeNode(rexBuilder, left); right = canonizeNode(rexBuilder, right); if (left.toString().compareTo(right.toString()) <= 0) { return rexBuilder.makeCall(call.getOperator(), left, right); } else { return rexBuilder.makeCall(call.getOperator(), right, left); } default: return condition; } }</code><technical_language>nit. L348 L349 merged a single one. below</technical_language>

Target:
private static RexNode canonizeNode(RexBuilder rexBuilder, RexNode condition) { switch (condition.getKind()) { case AND: case OR: { RexCall call = (RexCall) condition; SortedMap<String, RexNode> newOperands = new TreeMap<>(); for (RexNode operand : call.operands) { operand = canonizeNode(rexBuilder, operand); newOperands.put(operand.toString(), operand); } if (newOperands.size() < 2) { return newOperands.values().iterator().next(); } return rexBuilder.makeCall(call.getOperator(), ImmutableList.copyOf(newOperands.values())); } case EQUALS: case NOT_EQUALS: case LESS_THAN: case GREATER_THAN: case LESS_THAN_OR_EQUAL: case GREATER_THAN_OR_EQUAL: { RexCall call = (RexCall) condition; RexNode left = canonizeNode(rexBuilder, call.getOperands().get(0)); RexNode right = canonizeNode(rexBuilder, call.getOperands().get(1)); call = (RexCall) rexBuilder.makeCall(call.getOperator(), left, right); if (left.toString().compareTo(right.toString()) <= 0) { return call; } return RexUtil.invert(rexBuilder, call); } case PLUS: case TIMES: RexCall call = (RexCall) condition; RexNode left = call.getOperands().get(0); RexNode right = call.getOperands().get(1); left = canonizeNode(rexBuilder, left); right = canonizeNode(rexBuilder, right); RexNode newCall; if (left.toString().compareTo(right.toString()) <= 0) { newCall = rexBuilder.makeCall(call.getOperator(), left, right); } else { newCall = rexBuilder.makeCall(call.getOperator(), right, left); } if (!SqlTypeUtil.equalSansNullability(rexBuilder.getTypeFactory(), newCall.getType(), call.getType())) { newCall = call; } return newCall; default: return condition; } }