asolimando commented on code in PR #4557:
URL: https://github.com/apache/calcite/pull/4557#discussion_r2381636981


##########
core/src/main/java/org/apache/calcite/rex/RexUtil.java:
##########
@@ -1693,21 +1692,35 @@ public static boolean isLosslessCast(RexNode node) {
    * @return 'true' when the conversion can certainly be determined to be 
loss-less cast,
    *         but may return 'false' for some lossless casts.
    */
-  @API(since = "1.22", status = API.Status.EXPERIMENTAL)
+  @API(since = "1.22", status = API.Status.STABLE)
   public static boolean isLosslessCast(RelDataType source, RelDataType target) 
{
     final SqlTypeName sourceSqlTypeName = source.getSqlTypeName();
     final SqlTypeName targetSqlTypeName = target.getSqlTypeName();
-    // 1) Both INT numeric types
-    if (SqlTypeFamily.INTEGER.getTypeNames().contains(sourceSqlTypeName)
-        && SqlTypeFamily.INTEGER.getTypeNames().contains(targetSqlTypeName)) {
-      return targetSqlTypeName.compareTo(sourceSqlTypeName) >= 0;
+
+    // 1) Both integer types (signed or unsigned)
+    if (SqlTypeUtil.isIntType(source) && SqlTypeUtil.isIntType(target)) {
+      final boolean sourceIsUnsigned =
+          
SqlTypeFamily.UNSIGNED_NUMERIC.getTypeNames().contains(sourceSqlTypeName);
+      final boolean targetIsUnsigned =
+          
SqlTypeFamily.UNSIGNED_NUMERIC.getTypeNames().contains(targetSqlTypeName);
+      if (!sourceIsUnsigned && targetIsUnsigned) {
+        return false;
+      }
+      if (sourceIsUnsigned
+          && SqlTypeFamily.INTEGER.getTypeNames().contains(targetSqlTypeName)
+          && !SqlTypeUtil.integerRangeContains(target, source)) {
+        return false;
+      }
+      return SqlTypeUtil.integerRangeContains(target, source);

Review Comment:
   Good catch, I have realized and adapted the code to support unsigned after 
the fact and there might be glitches in the refactoring, I will do another pass



-- 
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: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to