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 6ac5e05b4e..4eb0895990 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 @@ -1193,6 +1193,14 @@ public class FunctionCallExpr extends Expr { } else if (fnName.getFunction().equalsIgnoreCase("if")) { Type[] childTypes = collectChildReturnTypes(); Type assignmentCompatibleType = ScalarType.getAssignmentCompatibleType(childTypes[1], childTypes[2], true); + if (assignmentCompatibleType.isDecimalV3()) { + if (childTypes[1].isDecimalV3() && !((ScalarType) childTypes[1]).equals(assignmentCompatibleType)) { + uncheckedCastChild(assignmentCompatibleType, 1); + } + if (childTypes[2].isDecimalV3() && !((ScalarType) childTypes[2]).equals(assignmentCompatibleType)) { + uncheckedCastChild(assignmentCompatibleType, 2); + } + } childTypes[1] = assignmentCompatibleType; childTypes[2] = assignmentCompatibleType; fn = getBuiltinFunction(fnName.getFunction(), childTypes, @@ -1200,6 +1208,8 @@ public class FunctionCallExpr extends Expr { if (assignmentCompatibleType.isDatetimeV2()) { fn.setReturnType(assignmentCompatibleType); } + + } else if (AggregateFunction.SUPPORT_ORDER_BY_AGGREGATE_FUNCTION_NAME_SET.contains( fnName.getFunction().toLowerCase())) { // order by elements add as child like windows function. so if we get the diff --git a/regression-test/data/datatype_p0/decimalv3/test_functions.out b/regression-test/data/datatype_p0/decimalv3/test_functions.out new file mode 100644 index 0000000000..6651ecd9af --- /dev/null +++ b/regression-test/data/datatype_p0/decimalv3/test_functions.out @@ -0,0 +1,5 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !select_default -- +10001 13.300000000 +10007 13.300000000 + diff --git a/regression-test/suites/datatype_p0/decimalv3/test_functions.groovy b/regression-test/suites/datatype_p0/decimalv3/test_functions.groovy new file mode 100644 index 0000000000..a0257e6441 --- /dev/null +++ b/regression-test/suites/datatype_p0/decimalv3/test_functions.groovy @@ -0,0 +1,53 @@ +// 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. + +import org.codehaus.groovy.runtime.IOGroovyMethods + +import java.nio.charset.StandardCharsets +import java.nio.file.Files +import java.nio.file.Paths + +suite("test_functions") { + def dbName = "test_functions" + sql "CREATE DATABASE IF NOT EXISTS ${dbName}" + sql "USE $dbName" + + def tableName = "test_decimal_load" + try { + sql """ DROP TABLE IF EXISTS ${tableName} """ + sql """ + CREATE TABLE IF NOT EXISTS ${tableName} ( + id int(11) NULL, + s_count int(11) NULL, + fee DECIMALV3(15,4) NULL + ) ENGINE=OLAP + DUPLICATE KEY(`id`) + COMMENT 'OLAP' + DISTRIBUTED BY HASH(`id`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + + sql """ INSERT INTO ${tableName} VALUES(10007,26,13.3), (10001,12,13.3) """ + qt_select_default """ SELECT id, if(1 = 2, + 1.0*s_count - fee, + fee) FROM ${tableName} t ORDER BY id; """ + } finally { + try_sql("DROP TABLE IF EXISTS ${tableName}") + } +}