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" }