mihaibudiu commented on code in PR #3663:
URL: https://github.com/apache/calcite/pull/3663#discussion_r1529449543
##########
core/src/main/java/org/apache/calcite/rex/RexLiteral.java:
##########
@@ -1060,22 +1065,46 @@ public boolean isNull() {
case BIGINT:
case INTEGER:
case SMALLINT:
- case TINYINT:
- case DOUBLE:
- case REAL:
- case FLOAT:
+ case TINYINT: {
+ BigDecimal bd = (BigDecimal) value;
if (clazz == Long.class) {
- return clazz.cast(((BigDecimal) value).longValue());
+ return clazz.cast(bd.longValue());
} else if (clazz == Integer.class) {
- return clazz.cast(((BigDecimal) value).intValue());
+ return clazz.cast(bd.intValue());
} else if (clazz == Short.class) {
- return clazz.cast(((BigDecimal) value).shortValue());
+ return clazz.cast(bd.shortValue());
} else if (clazz == Byte.class) {
- return clazz.cast(((BigDecimal) value).byteValue());
+ return clazz.cast(bd.byteValue());
} else if (clazz == Double.class) {
- return clazz.cast(((BigDecimal) value).doubleValue());
+ return clazz.cast(bd.doubleValue());
} else if (clazz == Float.class) {
- return clazz.cast(((BigDecimal) value).floatValue());
+ return clazz.cast(bd.floatValue());
+ }
+ break;
+ }
+ case DOUBLE:
+ case REAL:
+ case FLOAT:
+ if (value instanceof Double) {
+ Double d = (Double) value;
+ if (clazz == Long.class) {
+ return clazz.cast(d.longValue());
+ } else if (clazz == Integer.class) {
+ return clazz.cast(d.intValue());
+ } else if (clazz == Short.class) {
+ return clazz.cast(d.shortValue());
+ } else if (clazz == Byte.class) {
+ return clazz.cast(d.byteValue());
+ } else if (clazz == Double.class) {
+ return clazz.cast(d);
Review Comment:
Yes, it is, but the return type must be T, so the cast is necessary anyway.
The Java compiler isn't smart enough to understand that.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]