asolimando commented on code in PR #4557:
URL: https://github.com/apache/calcite/pull/4557#discussion_r2381976249
##########
core/src/main/java/org/apache/calcite/rex/RexUtil.java:
##########
@@ -1718,7 +1731,71 @@ public static boolean isLosslessCast(RelDataType source,
RelDataType target) {
final int targetPrecision = target.getPrecision();
return targetPrecision == PRECISION_NOT_SPECIFIED || targetPrecision >=
sourceLength;
}
- // Return FALSE by default
+
+ // 4) DECIMAL -> DECIMAL
+ if (sourceSqlTypeName == SqlTypeName.DECIMAL
+ && targetSqlTypeName == SqlTypeName.DECIMAL) {
+ int sourcePrecision = source.getPrecision();
+ int sourceScale = Math.max(source.getScale(), 0);
+ int targetPrecision = target.getPrecision();
+ int targetScale = Math.max(target.getScale(), 0);
+ if (sourcePrecision <= 0 || targetPrecision <= 0) {
+ return false;
+ }
+ return targetScale >= sourceScale
+ && (targetPrecision - targetScale) >= (sourcePrecision -
sourceScale);
+ }
+
+ // 5) integer family (signed or unsigned) -> DECIMAL
+ if (SqlTypeUtil.isIntType(source)
+ && targetSqlTypeName == SqlTypeName.DECIMAL) {
+ int targetPrecision = target.getPrecision();
+ int targetScale = Math.max(target.getScale(), 0);
+ int sourcePrecision = source.getPrecision();
+ if (sourcePrecision <= 0) {
Review Comment:
Plot twist, the assertion is not passing for these two tests:
- JdbcTest::testMinAggWithDouble()
- EnumerableBatchNestedLoopJoinTest::doubleInnerBatchJoinTestSQL()
`JavaType(int)` has an unspecified precision, and [apparently it's
intended](https://github.com/apache/calcite/blob/73c5400111b2ba502bf28d20aafbb609520ab56b/core/src/main/java/org/apache/calcite/rel/type/RelDataTypeSystem.java#L249),
so I am putting back the checks as they were
--
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]