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

xuyang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 8f98357c0b [fix](array-type) disable cast function to array type on 
origin exec engine. (#11602)
8f98357c0b is described below

commit 8f98357c0b573423940775514db9f6831436a867
Author: xy720 <22125576+xy...@users.noreply.github.com>
AuthorDate: Mon Aug 15 21:30:56 2022 +0800

    [fix](array-type) disable cast function to array type on origin exec 
engine. (#11602)
    
    This commit disable cast to array type on origin exec engine, except cast 
varchar to array type.
---
 .../java/org/apache/doris/analysis/CastExpr.java   |  10 +-
 ...=> test_cast_array_functions_by_literal.groovy} | 121 +++++++++++++++++++++
 2 files changed, 130 insertions(+), 1 deletion(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java
index bb1f8f4ef6..8b63d461ff 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java
@@ -29,6 +29,7 @@ import org.apache.doris.catalog.ScalarType;
 import org.apache.doris.catalog.Type;
 import org.apache.doris.common.AnalysisException;
 import org.apache.doris.common.Pair;
+import org.apache.doris.common.util.VectorizedUtil;
 import org.apache.doris.qe.ConnectContext;
 import org.apache.doris.thrift.TExpr;
 import org.apache.doris.thrift.TExprNode;
@@ -300,10 +301,17 @@ public class CastExpr extends Expr {
                         searchDesc, Function.CompareMode.IS_IDENTICAL);
             }
         } else if (type.isArrayType()) {
-            fn = ScalarFunction.createBuiltin(getFnName(Type.ARRAY),
+            if (VectorizedUtil.isVectorized()) {
+                // Vec engine don't need a scala cast function, but we still 
create one to pass the check.
+                fn = ScalarFunction.createBuiltin("CAST", type,  
Lists.newArrayList(), false,
+                    "", null, null, true);
+            } else if (childType.isVarchar()) {
+                // only support varchar cast to array for origin exec engine.
+                fn = ScalarFunction.createBuiltin(getFnName(Type.ARRAY),
                     type, Function.NullableMode.ALWAYS_NULLABLE,
                     Lists.newArrayList(Type.VARCHAR), false,
                     "doris::CastFunctions::cast_to_array_val", null, null, 
true);
+            }
         }
 
         if (fn == null) {
diff --git 
a/regression-test/suites/query/sql_functions/array_functions/test_cast_array_functions.groovy
 
b/regression-test/suites/query/sql_functions/array_functions/test_cast_array_functions_by_literal.groovy
similarity index 51%
rename from 
regression-test/suites/query/sql_functions/array_functions/test_cast_array_functions.groovy
rename to 
regression-test/suites/query/sql_functions/array_functions/test_cast_array_functions_by_literal.groovy
index 83f891f9ee..e046987202 100644
--- 
a/regression-test/suites/query/sql_functions/array_functions/test_cast_array_functions.groovy
+++ 
b/regression-test/suites/query/sql_functions/array_functions/test_cast_array_functions_by_literal.groovy
@@ -113,4 +113,125 @@ suite("test_cast_array_functions", "query") {
         exception "errCode = 2,"
     }
 
+    // Not Vectorized Engine
+    sql """ set enable_vectorized_engine = false """
+
+    //  ========== cast scalar to array ===========
+
+    test {
+        sql "select cast(cast('x' as char) as array<char>)"
+        // check exception message contains
+        exception "errCode = 2,"
+    }
+
+    test {
+        sql "select cast(cast('x' as string) as array<string>)"
+        // check exception message contains
+        exception "errCode = 2,"
+    }
+
+    test {
+        sql "select cast(1 as array<int>)"
+        // check exception message contains
+        exception "errCode = 2,"
+    }
+
+    test {
+        sql "select cast(999.999 as array<double>)"
+        // check exception message contains
+        exception "errCode = 2,"
+    }
+
+    test {
+        sql "select cast(cast(999.999 as double) as array<double>)"
+        // check exception message contains
+        exception "errCode = 2,"
+    }
+
+    test {
+        sql "select cast(cast(999.999 as decimal) as array<decimal>)"
+        // check exception message contains
+        exception "errCode = 2,"
+    }
+    //  ========== cast array to scalar ===========
+
+    test {
+        sql "select cast(['x'] as char)"
+        // check exception message contains
+        exception "errCode = 2,"
+    }
+
+    test {
+        sql "select cast(['x'] as varchar)"
+        // check exception message contains
+        exception "errCode = 2,"
+    }
+
+    test {
+        sql "select cast(['x'] as string)"
+        // check exception message contains
+        exception "errCode = 2,"
+    }
+
+    test {
+        sql "select cast([0] as int)"
+        // check exception message contains
+        exception "errCode = 2,"
+    }
+
+    test {
+        sql "select cast([999.999] as double)"
+        // check exception message contains
+        exception "errCode = 2,"
+    }
+
+    test {
+        sql "select cast([999.999] as decimal)"
+        // check exception message contains
+        exception "errCode = 2,"
+    }
+
+    //  ========== cast array to array ===========
+    test {
+        sql "select cast(['x'] as array<int>)"
+        // check exception message contains
+        exception "errCode = 2,"
+    }
+
+    test {
+        sql "select cast([0] as array<int>)"
+        // check exception message contains
+        exception "errCode = 2,"
+    }
+
+    test {
+        sql "select cast(['1'] as array<tinyint>)"
+        // check exception message contains
+        exception "errCode = 2,"
+    }
+
+    test {
+        sql "select cast(['100'] as array<smallint>)"
+        // check exception message contains
+        exception "errCode = 2,"
+    }
+
+    test {
+        sql "select cast([999.999] as array<double>)"
+        // check exception message contains
+        exception "errCode = 2,"
+    }
+
+    test {
+        sql "select cast([1] as array<char>)"
+        // check exception message contains
+        exception "errCode = 2,"
+    }
+
+    test {
+        sql "select cast([1] as array<varchar>)"
+        // check exception message contains
+        exception "errCode = 2,"
+    }
+    
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to