From 97a10d2a6b9cde6ffb58471438c5334f795da89d Mon Sep 17 00:00:00 2001 From: morrySnow <101034200+morrySnow@users.noreply.github.com> Date: Mon, 13 May 2024 14:42:04 +0800 Subject: [PATCH] [fix](Nereids) cast from json should always nullable (#34707) --- .../doris/nereids/trees/expressions/Cast.java | 2 ++ .../suites/query_p0/cast/test_cast.groovy | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Cast.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Cast.java index 76cb1826e55113..62bd3639b5a244 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Cast.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/Cast.java @@ -79,6 +79,8 @@ public boolean nullable() { return true; } else if (!childDataType.isTimeLikeType() && targetType.isTimeLikeType()) { return true; + } else if (childDataType.isJsonType()) { + return true; } else { return child().nullable(); } diff --git a/regression-test/suites/query_p0/cast/test_cast.groovy b/regression-test/suites/query_p0/cast/test_cast.groovy index c0df52b39e7ddf..2fe4d53eb80a09 100644 --- a/regression-test/suites/query_p0/cast/test_cast.groovy +++ b/regression-test/suites/query_p0/cast/test_cast.groovy @@ -145,4 +145,22 @@ suite('test_cast', "arrow_flight_sql") { sql "select * from ${tbl} where case when k0 = 101 then 'true' else 1 end" result([[101]]) } + + sql "DROP TABLE IF EXISTS test_json" + sql """ + CREATE TABLE IF NOT EXISTS test_json ( + id INT not null, + j JSON not null + ) + DUPLICATE KEY(id) + DISTRIBUTED BY HASH(id) BUCKETS 10 + PROPERTIES("replication_num" = "1"); + """ + + sql """ + INSERT INTO test_json VALUES(26, '{"k1":"v1", "k2": 200}'); + """ + sql "sync" + sql "Select cast(j as int) from test_json" + sql "DROP TABLE IF EXISTS test_json" }