in modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/exp/RexToLixTranslator.java [658:755]
public static Expression translateLiteral(
RexLiteral literal,
RelDataType type,
JavaTypeFactory typeFactory,
RexImpTable.NullAs nullAs) {
if (literal.isNull()) {
switch (nullAs) {
case TRUE:
case IS_NULL:
return RexImpTable.TRUE_EXPR;
case FALSE:
case IS_NOT_NULL:
return RexImpTable.FALSE_EXPR;
case NOT_POSSIBLE:
throw new ControlFlowException();
case NULL:
default:
return RexImpTable.NULL_EXPR;
}
}
else {
switch (nullAs) {
case IS_NOT_NULL:
return RexImpTable.TRUE_EXPR;
case IS_NULL:
return RexImpTable.FALSE_EXPR;
}
}
Type javaCls = typeFactory.getJavaClass(type);
final Object value2;
switch (literal.getType().getSqlTypeName()) {
case DECIMAL:
final BigDecimal bd = literal.getValueAs(BigDecimal.class);
if (javaCls == float.class)
return Expressions.constant(bd, javaCls);
else if (javaCls == double.class)
return Expressions.constant(bd, javaCls);
assert javaCls == BigDecimal.class;
return Expressions.call(
IgniteSqlFunctions.class,
"toBigDecimal",
/*
The ConstantExpression class, when converting from BigDecimal to Bigdecimal,
removes trailing zeros from the original object, regardless of the original scale value.
Therefore, BigDecimal must be converted to a string to avoid this.
*/
Expressions.constant(bd.toString()),
Expressions.constant(type.getPrecision()),
Expressions.constant(type.getScale()));
case DATE:
case TIME:
case TIME_WITH_LOCAL_TIME_ZONE:
case INTERVAL_YEAR:
case INTERVAL_YEAR_MONTH:
case INTERVAL_MONTH:
value2 = literal.getValueAs(Integer.class);
javaCls = int.class;
break;
case TIMESTAMP:
case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
case INTERVAL_DAY:
case INTERVAL_DAY_HOUR:
case INTERVAL_DAY_MINUTE:
case INTERVAL_DAY_SECOND:
case INTERVAL_HOUR:
case INTERVAL_HOUR_MINUTE:
case INTERVAL_HOUR_SECOND:
case INTERVAL_MINUTE:
case INTERVAL_MINUTE_SECOND:
case INTERVAL_SECOND:
value2 = literal.getValueAs(Long.class);
javaCls = long.class;
break;
case CHAR:
case VARCHAR:
value2 = literal.getValueAs(String.class);
break;
case BINARY:
case VARBINARY:
return Expressions.new_(
ByteString.class,
Expressions.constant(
literal.getValueAs(byte[].class),
byte[].class));
case GEOMETRY:
throw new IllegalStateException("Unsupported data type: " + literal.getType());
case SYMBOL:
value2 = literal.getValueAs(Enum.class);
javaCls = value2.getClass();
break;
default:
final Primitive primitive = Primitive.ofBoxOr(javaCls);
final Comparable val = literal.getValueAs(Comparable.class);
value2 = primitive != null && val instanceof Number ? primitive.number((Number)val) : val;
}
return Expressions.constant(value2, javaCls);
}