From 46dc0d21923614a83ef0f4d82be222a1c1ec6da7 Mon Sep 17 00:00:00 2001 From: amory Date: Fri, 16 Aug 2024 09:47:44 +0800 Subject: [PATCH] [fix](variant) fix variant cast (#39426) ## Proposed changes backport: https://github.com/apache/doris/pull/39377 Issue Number: close #xxx --- .../org/apache/doris/nereids/trees/expressions/Cast.java | 2 ++ regression-test/suites/query_p0/cast/test_cast.groovy | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) 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 124ed589d4..9122f0f4ad 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 @@ -81,6 +81,8 @@ public class Cast extends Expression implements UnaryExpression { return true; } else if (childDataType.isJsonType() || targetType.isJsonType()) { return true; + } else if (childDataType.isVariantType() || targetType.isVariantType()) { + 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 2fe4d53eb8..dae669e296 100644 --- a/regression-test/suites/query_p0/cast/test_cast.groovy +++ b/regression-test/suites/query_p0/cast/test_cast.groovy @@ -150,7 +150,8 @@ suite('test_cast', "arrow_flight_sql") { sql """ CREATE TABLE IF NOT EXISTS test_json ( id INT not null, - j JSON not null + j JSON not null, + v variant not null ) DUPLICATE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 10 @@ -158,9 +159,10 @@ suite('test_cast', "arrow_flight_sql") { """ sql """ - INSERT INTO test_json VALUES(26, '{"k1":"v1", "k2": 200}'); + INSERT INTO test_json VALUES(26, '{"k1":"v1", "k2": 200}', '[\"asd]'); """ sql "sync" sql "Select cast(j as int) from test_json" + sql "select cast(v as int) from test_json" sql "DROP TABLE IF EXISTS test_json" }