// parameters and literal nulls have no type, so just set the type -- they'll be polymorphic about it.
if (expression instanceof ParameterExpression) {
targetInstance = targetInstance.withNullable(true);
CastExpression castExpression =
newCastExpression(expression, targetInstance);
castExpression.setPreptimeValue(new TPreptimeValue(targetInstance));
parametersSync.set(expression, targetInstance);
return castExpression;
}
if (expression instanceof NullSource) {
ValueSource nullSource = ValueSources.getNullSource(targetInstance);
expression.setPreptimeValue(new TPreptimeValue(targetInstance, nullSource));
return expression;
}
if (equalForCast(targetInstance, type(expression)))
return expression;
DataTypeDescriptor sqlType = expression.getSQLtype();
targetInstance = targetInstance.withNullable(sqlType == null || sqlType.isNullable());
CastExpression castExpression =
newCastExpression(expression, targetInstance);
castExpression.setPreptimeValue(new TPreptimeValue(targetInstance));
ExpressionNode result = finishCast(castExpression, folder, parametersSync);
result = folder.foldConstants(result);
return result;
}