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

eldenmoon 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 a8dcca98ec8 [FIX](explode)fix explode array decimal (#28744)
a8dcca98ec8 is described below

commit a8dcca98ec8d51c0b64b55d3305cd7884c16d331
Author: amory <wangqian...@selectdb.com>
AuthorDate: Wed Dec 20 20:19:56 2023 +0800

    [FIX](explode)fix explode array decimal (#28744)
    
    * fix explode with array<decimal> has specific precision at old planner
---
 .../main/java/org/apache/doris/catalog/Type.java   |  1 +
 .../apache/doris/analysis/FunctionCallExpr.java    | 21 ++++++-
 .../java/org/apache/doris/catalog/FunctionSet.java |  3 +
 .../table_function/explode_array_decimal.out       |  7 +++
 .../table_function/explode_array_decimal.groovy    | 68 ++++++++++++++++++++++
 5 files changed, 98 insertions(+), 2 deletions(-)

diff --git a/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java 
b/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java
index 981f5bb61e6..ab9b56c5aa5 100644
--- a/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java
+++ b/fe/fe-common/src/main/java/org/apache/doris/catalog/Type.java
@@ -103,6 +103,7 @@ public abstract class Type {
     public static final ScalarType DECIMAL64 = DEFAULT_DECIMAL64;
     public static final ScalarType DECIMAL128 = DEFAULT_DECIMAL128;
     public static final ScalarType DECIMAL256 = DEFAULT_DECIMAL256;
+    public static final ScalarType WILDCARD_DECIMAL = 
ScalarType.createDecimalType(-1, -1);
     public static final ScalarType JSONB = new ScalarType(PrimitiveType.JSONB);
     // (ScalarType) ScalarType.createDecimalTypeInternal(-1, -1);
     public static final ScalarType DEFAULT_VARCHAR = 
ScalarType.createVarcharType(-1);
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
index f63b4104301..c35b367f9bd 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FunctionCallExpr.java
@@ -1618,8 +1618,25 @@ public class FunctionCallExpr extends Expr {
             // now first find table function in table function sets
             if (isTableFnCall) {
                 Type[] childTypes = collectChildReturnTypes();
-                fn = getTableFunction(fnName.getFunction(), childTypes,
-                        Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF);
+                // when we call explode<Array<Decimal>> with nested decimal 
has specific precision and scale,
+                // collectChildReturnTypes will return specific precision and 
scale decimal type witch may not match
+                // builtln func we defined in fe code, because we make 
array_support_type is actual origin type.here we
+                // temp write this if to get matched explode function and then 
set actually decimal type from sql to
+                // func return type. if we switch nereid would hasn't this 
problems.
+                if (fnName.getFunction().equalsIgnoreCase("explode") && 
childTypes[0].isArrayType()) {
+                    // get origin type to match builtln func
+                    Type[] matchFuncChildTypes = getActualArgTypes(childTypes);
+                    fn = getTableFunction(fnName.getFunction(), 
matchFuncChildTypes,
+                            Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF);
+                    if (fn == null) {
+                        throw new 
AnalysisException(getFunctionNotFoundError(argTypes));
+                    }
+                    // set param child types
+                    fn.setReturnType(((ArrayType) 
childTypes[0]).getItemType());
+                } else {
+                    fn = getTableFunction(fnName.getFunction(), childTypes,
+                            Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF);
+                }
                 if (fn == null) {
                     throw new 
AnalysisException(getFunctionNotFoundError(argTypes));
                 }
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java
index e18370560c3..e5ae0d50284 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java
@@ -1772,6 +1772,9 @@ public class FunctionSet<T> {
                     Lists.newArrayList(new ArrayType(subType)), false,
                     
"_ZN5doris19DummyTableFunctions7explodeEPN9doris_udf15FunctionContextERKNS1_13CollectionValE");
         }
+        addTableFunctionWithCombinator(EXPLODE, Type.WILDCARD_DECIMAL, 
Function.NullableMode.ALWAYS_NULLABLE,
+                Lists.newArrayList(new ArrayType(Type.WILDCARD_DECIMAL)), 
false,
+                
"_ZN5doris19DummyTableFunctions7explodeEPN9doris_udf15FunctionContextERKNS1_13CollectionValE");
     }
 
     public boolean isAggFunctionName(String name) {
diff --git 
a/regression-test/data/query_p0/sql_functions/table_function/explode_array_decimal.out
 
b/regression-test/data/query_p0/sql_functions/table_function/explode_array_decimal.out
new file mode 100644
index 00000000000..3e5e665535c
--- /dev/null
+++ 
b/regression-test/data/query_p0/sql_functions/table_function/explode_array_decimal.out
@@ -0,0 +1,7 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !sql_old_planner --
+0.800  
[0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,1,9,5,5,5,5,5,5,5,5,5,0.8,0.8,0.8,0.8,0.8]
+
+-- !sql_nereid --
+0.800  
[0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,1,9,5,5,5,5,5,5,5,5,5,0.8,0.8,0.8,0.8,0.8]
+
diff --git 
a/regression-test/suites/query_p0/sql_functions/table_function/explode_array_decimal.groovy
 
b/regression-test/suites/query_p0/sql_functions/table_function/explode_array_decimal.groovy
new file mode 100644
index 00000000000..60eed6b2020
--- /dev/null
+++ 
b/regression-test/suites/query_p0/sql_functions/table_function/explode_array_decimal.groovy
@@ -0,0 +1,68 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("explode_array_decimal") {
+    sql "DROP TABLE IF EXISTS ods_device_data_1d_inc;"
+
+    sql """
+    CREATE TABLE `ods_device_data_1d_inc` (
+                                              `id` INT NULL,
+                                              `electricityPrice` VARCHAR(5000) 
NULL
+    ) ENGINE=OLAP
+    DUPLICATE KEY(`id`, `electricityPrice`)
+    COMMENT 'OLAP'
+    DISTRIBUTED BY HASH(`id`) BUCKETS 10
+    PROPERTIES (
+    "replication_allocation" = "tag.location.default: 1",
+    "min_load_replica_num" = "-1",
+    "is_being_synced" = "false",
+    "storage_format" = "V2",
+    "light_schema_change" = "true",
+    "disable_auto_compaction" = "false",
+    "enable_single_replica_compaction" = "false",
+    "group_commit_interval_ms" = "10000"
+    );"""
+
+    sql """insert into ods_device_data_1d_inc values(1, 
"[0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,0.8,1,9,5,5,5,5,5,5,5,5,5,0.8,0.8,0.8,0.8,0.8]")"""
+
+    sql "SET enable_nereids_planner=false;"
+
+    qt_sql_old_planner """
+    SELECT * from
+        (
+            select
+                e1,t.electricityPrice
+            from
+                ods_device_data_1d_inc as t
+                lateral view explode(cast (electricityPrice as 
ARRAY<DECIMAL(10,3)>)) tmp1 as e1
+        ) kk limit 1
+        """
+
+    sql 'set enable_fallback_to_original_planner=false'
+    sql 'set enable_nereids_planner=true'
+
+    qt_sql_nereid """
+        SELECT * from
+            (
+                select
+                    e1,t.electricityPrice
+                from
+                    ods_device_data_1d_inc as t
+                    lateral view explode(cast (electricityPrice as 
ARRAY<DECIMAL(10,3)>)) tmp1 as e1
+            ) kk limit 1
+            """
+}


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

Reply via email to