This is an automated email from the ASF dual-hosted git repository.

yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-2.1 by this push:
     new 46dc0d21923 [fix](variant) fix variant cast (#39426)
46dc0d21923 is described below

commit 46dc0d21923614a83ef0f4d82be222a1c1ec6da7
Author: amory <[email protected]>
AuthorDate: Fri Aug 16 09:47:44 2024 +0800

    [fix](variant) fix variant cast (#39426)
    
    ## Proposed changes
    backport: https://github.com/apache/doris/pull/39377
    Issue Number: close #xxx
    
    <!--Describe your changes.-->
---
 .../main/java/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 124ed589d49..9122f0f4adb 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 2fe4d53eb80..dae669e2965 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"
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to