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


##########
core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java:
##########
@@ -556,6 +557,96 @@ public static boolean isExactNumeric(RelDataType type) {
     }
   }
 
+  /**
+   * Returns whether {@code container} can represent every value produced by
+   * {@code content} without loss of information.
+   *
+   * <p>The {@code container} type must be one of the integer types (signed or
+   * unsigned). The {@code content} type can be integer, or a DECIMAL with
+   * scale {@code 0}. For all other types this method returns {@code false}.
+   *
+   * @throws IllegalArgumentException if {@code container} is not an integer 
type
+   */
+  @API(since = "1.40", status = API.Status.EXPERIMENTAL)
+  public static boolean integerRangeContains(RelDataType container,
+      RelDataType content) {
+    checkArgument(isIntType(container),
+        "container must be an integer type: %s", container);
+
+    final SqlTypeName contentType = content.getSqlTypeName();
+    if (contentType == null) {
+      return false;
+    }
+    final boolean contentIsDecimal = contentType == SqlTypeName.DECIMAL;
+    if (!isIntType(content)) {
+      if (!contentIsDecimal || content.getScale() != 0) {
+        return false;
+      }
+    }
+
+    final BigInteger containerMin = integerBound(container, false);
+    final BigInteger containerMax = integerBound(container, true);
+    if (containerMin == null || containerMax == null) {

Review Comment:
   You mean that for the types we handle (int for `container` and int+dec with 
scale 0 for `content`) we will never return `null` and can omit the check?
   
   I haven't looked in details at the `limit` method but I'd rather bail out 
safely in case we get a `null`, whatever the reason.



-- 
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]

Reply via email to