mihaibudiu commented on code in PR #4557:
URL: https://github.com/apache/calcite/pull/4557#discussion_r2383070437
##########
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:
sorry about the extra work, I will try to remember this
--
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]