[CALCITE-7156] OFFSET and FETCH in EnumerableLimit need to support BIGINT
diff --git a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableLimit.java b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableLimit.java
index 5958e5d..3c046de 100644
--- a/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableLimit.java
+++ b/core/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableLimit.java
@@ -127,6 +127,9 @@ static Expression getExpression(RexNode rexNode) {
Expressions.constant("?" + param.getIndex())),
Integer.class);
} else {
+ // TODO: Enumerable runtime only supports INT types for FETCH and OFFSET, not BIGINT types.
+ // Currently, using BIGINT types for execution will result in an error message.
+ // This issue needs to be fixed. For more information, see CALCITE-7156.
return Expressions.constant(RexLiteral.intValue(rexNode));
}
}
diff --git a/core/src/main/java/org/apache/calcite/rex/RexLiteral.java b/core/src/main/java/org/apache/calcite/rex/RexLiteral.java
index a79e108..ce7ac68 100644
--- a/core/src/main/java/org/apache/calcite/rex/RexLiteral.java
+++ b/core/src/main/java/org/apache/calcite/rex/RexLiteral.java
@@ -1275,6 +1275,11 @@ public static Number numberValue(RexNode node) {
* never null. */
public static int intValue(RexNode node) {
final Number number = numberValue(node);
+ long longValue = number.longValue();
+ if (longValue > Integer.MAX_VALUE || longValue < Integer.MIN_VALUE) {
+ throw new ArithmeticException(
+ "Integer overflow: " + longValue + " is out of range for INT");
+ }
return number.intValue();
}
diff --git a/core/src/test/resources/sql/sort.iq b/core/src/test/resources/sql/sort.iq
index 32f75d2..ea61952 100644
--- a/core/src/test/resources/sql/sort.iq
+++ b/core/src/test/resources/sql/sort.iq
@@ -417,4 +417,9 @@
!ok
+# [CALCITE-7156] OFFSET and FETCH in EnumerableLimit need to support BIGINT
+select * from "hr"."emps" limit 3000000000 offset 2500000000;
+Caused by: java.lang.ArithmeticException: Integer overflow: 3000000000 is out of range for INT
+!error
+
# End sort.iq