From 9fb125b73172264bb1c44d7f36c125bfc7f69ce3 Mon Sep 17 00:00:00 2001 From: yuzelin Date: Wed, 13 Nov 2024 15:37:48 +0800 Subject: [PATCH] [common] Fix overflow problem of NumericToBooleanCastRule --- .../org/apache/paimon/casting/NumericToBooleanCastRule.java | 2 +- .../test/java/org/apache/paimon/flink/SchemaChangeITCase.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/paimon-common/src/main/java/org/apache/paimon/casting/NumericToBooleanCastRule.java b/paimon-common/src/main/java/org/apache/paimon/casting/NumericToBooleanCastRule.java index 06fa89fe3599..5b47741e6d35 100644 --- a/paimon-common/src/main/java/org/apache/paimon/casting/NumericToBooleanCastRule.java +++ b/paimon-common/src/main/java/org/apache/paimon/casting/NumericToBooleanCastRule.java @@ -37,6 +37,6 @@ private NumericToBooleanCastRule() { @Override public CastExecutor create(DataType inputType, DataType targetType) { - return value -> value.intValue() != 0; + return value -> value.longValue() != 0; } } diff --git a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/SchemaChangeITCase.java b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/SchemaChangeITCase.java index ba161fe84008..a2ef1d5c8ace 100644 --- a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/SchemaChangeITCase.java +++ b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/SchemaChangeITCase.java @@ -251,7 +251,8 @@ public void testModifyColumnTypeFromNumericToDecimal() { public void testModifyColumnTypeBooleanAndNumeric() { // boolean To numeric and numeric To boolean sql("CREATE TABLE T (a BOOLEAN, b BOOLEAN, c TINYINT, d INT, e BIGINT, f DOUBLE)"); - sql("INSERT INTO T VALUES(true, false, cast(0 as TINYINT), 1 , 123, 3.14)"); + sql( + "INSERT INTO T VALUES(true, false, cast(0 as TINYINT), 1 , -9223372036854775808, 3.14)"); sql("ALTER TABLE T MODIFY (a TINYINT, b INT, c BOOLEAN, d BOOLEAN, e BOOLEAN)"); List result = sql("SHOW CREATE TABLE T");