in core/src/main/java/org/apache/calcite/rex/RexSimplify.java [265:339]
RexNode simplify(RexNode e, RexUnknownAs unknownAs) {
if (STRONG.isNull(e)) {
// Only boolean NULL (aka UNKNOWN) can be converted to FALSE. Even in
// unknownAs=FALSE mode, we must not convert a NULL integer (say) to FALSE
if (e.getType().getSqlTypeName() == SqlTypeName.BOOLEAN) {
switch (unknownAs) {
case FALSE:
case TRUE:
return rexBuilder.makeLiteral(unknownAs.toBoolean());
default:
break;
}
}
return rexBuilder.makeNullLiteral(e.getType());
}
switch (e.getKind()) {
case AND:
return simplifyAnd((RexCall) e, unknownAs);
case OR:
return simplifyOr((RexCall) e, unknownAs);
case NOT:
return simplifyNot((RexCall) e, unknownAs);
case CASE:
return simplifyCase((RexCall) e, unknownAs);
case COALESCE:
return simplifyCoalesce((RexCall) e);
case CAST:
case SAFE_CAST:
return simplifyCast((RexCall) e);
case CEIL:
case FLOOR:
return simplifyCeilFloor((RexCall) e);
case IS_NULL:
case IS_NOT_NULL:
case IS_TRUE:
case IS_NOT_TRUE:
case IS_FALSE:
case IS_NOT_FALSE:
assert e instanceof RexCall;
return simplifyIs((RexCall) e, unknownAs);
case EQUALS:
case GREATER_THAN:
case GREATER_THAN_OR_EQUAL:
case LESS_THAN:
case LESS_THAN_OR_EQUAL:
case NOT_EQUALS:
return simplifyComparison((RexCall) e, unknownAs);
case SEARCH:
return simplifySearch((RexCall) e, unknownAs);
case LIKE:
return simplifyLike((RexCall) e, unknownAs);
case MINUS_PREFIX:
case CHECKED_MINUS_PREFIX:
return simplifyUnaryMinus((RexCall) e, unknownAs);
case PLUS_PREFIX:
return simplifyUnaryPlus((RexCall) e, unknownAs);
case PLUS:
case MINUS:
case TIMES:
case DIVIDE:
case CHECKED_PLUS:
case CHECKED_MINUS:
case CHECKED_TIMES:
case CHECKED_DIVIDE:
return simplifyArithmetic((RexCall) e);
case M2V:
return simplifyM2v((RexCall) e);
default:
if (e.getClass() == RexCall.class) {
return simplifyGenericNode((RexCall) e);
} else {
return e;
}
}
}