Skip to content

Commit 9b35211

Browse files
committed
[CALCITE-7398] Incorrect int cast in VariantNonNull#cast for BIGINT
Signed-off-by: Heng Qian <[email protected]>
1 parent 8a286c5 commit 9b35211

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

core/src/main/java/org/apache/calcite/runtime/variant/VariantNonNull.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public class VariantNonNull extends VariantSqlValue {
286286
break;
287287
}
288288
case BIGINT: {
289-
long l = (int) value;
289+
long l = (long) value;
290290
switch (type.getTypeName()) {
291291
case TINYINT:
292292
case SMALLINT:

testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,6 +1868,8 @@ void testCastToBoolean(CastType castType, SqlOperatorFixture f) {
18681868
"INTEGER ARRAY");
18691869
f.checkScalar("cast(cast('abc' as VARIANT) AS VARCHAR)", "abc", "VARCHAR");
18701870
f.checkScalar("cast(cast('abc' as VARIANT) AS CHAR(3))", "abc", "CHAR(3)");
1871+
// Test for [CALCITE-7398] Incorrect int cast in VariantNonNull#cast for BIGINT
1872+
f.checkScalar("cast(cast(2147483648 as VARIANT) as DECIMAL)", "2147483648", "DECIMAL(19, 0)");
18711873

18721874
// Converting a variant to anything that does not match the runtime type returns null
18731875
f.checkScalar("cast(cast(1 as VARIANT) as INTEGER)", "1", "INTEGER");

0 commit comments

Comments
 (0)