From 3dcdadcea656991839c9e7ffed4beb20ae4f0149 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Mon, 22 May 2023 22:48:44 +0800 Subject: [PATCH] [Improvement](function) support decimalv3 for function `least` and `greatest` (#19931) --- be/src/vec/functions/least_greast.cpp | 26 +++++++++++++++++-- .../doris/analysis/FunctionCallExpr.java | 4 ++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/be/src/vec/functions/least_greast.cpp b/be/src/vec/functions/least_greast.cpp index 26f168ad68..90f8fa99cf 100644 --- a/be/src/vec/functions/least_greast.cpp +++ b/be/src/vec/functions/least_greast.cpp @@ -110,7 +110,7 @@ struct CompareMultiImpl { } \ } NUMERIC_TYPE_TO_COLUMN_TYPE(DISPATCH) - DISPATCH(Decimal128, ColumnDecimal) + DECIMAL_TYPE_TO_COLUMN_TYPE(DISPATCH) TIME_TYPE_TO_COLUMN_TYPE(DISPATCH) #undef DISPATCH } @@ -136,6 +136,17 @@ private: ? column_raw_data[index_check_const(i, ArgConst)] : result_raw_data[i]; } + } else if constexpr (std::is_same_v || + std::is_same_v || + std::is_same_v) { + for (size_t i = 0; i < input_rows_count; ++i) { + using type = std::decay_t; + result_raw_data[i] = + Op::apply(column_raw_data[index_check_const(i, ArgConst)].value, + result_raw_data[i].value) + ? column_raw_data[index_check_const(i, ArgConst)] + : result_raw_data[i]; + } } else { for (size_t i = 0; i < input_rows_count; ++i) { using type = std::decay_t; @@ -204,7 +215,7 @@ struct FunctionFieldImpl { } \ } NUMERIC_TYPE_TO_COLUMN_TYPE(DISPATCH) - DISPATCH(Decimal128, ColumnDecimal) + DECIMAL_TYPE_TO_COLUMN_TYPE(DISPATCH) TIME_TYPE_TO_COLUMN_TYPE(DISPATCH) #undef DISPATCH } @@ -230,6 +241,17 @@ private: first_raw_data[index_check_const(i, ArgConst)], arg_data)) * col); } + } else if constexpr (std::is_same_v || + std::is_same_v || + std::is_same_v) { + for (size_t i = 0; i < input_rows_count; ++i) { + using type = std::decay_t; + res_data[i] |= (!res_data[i] * + (EqualsOp::apply( + first_raw_data[index_check_const(i, ArgConst)].value, + arg_data.value)) * + col); + } } else { for (size_t i = 0; i < input_rows_count; ++i) { using type = std::decay_t; 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 51abe66cbc..1238c8514e 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 @@ -1403,7 +1403,9 @@ public class FunctionCallExpr extends Expr { } fn = getBuiltinFunction(fnName.getFunction(), childTypes, Function.CompareMode.IS_NONSTRICT_SUPERTYPE_OF); - } else if (fnName.getFunction().equalsIgnoreCase("coalesce") && children.size() > 1) { + } else if ((fnName.getFunction().equalsIgnoreCase("coalesce") + || fnName.getFunction().equalsIgnoreCase("greatest") + || fnName.getFunction().equalsIgnoreCase("least")) && children.size() > 1) { Type[] childTypes = collectChildReturnTypes(); Type assignmentCompatibleType = childTypes[0]; for (int i = 1; i < childTypes.length && assignmentCompatibleType.isDecimalV3(); i++) {