This is an automated email from the ASF dual-hosted git repository. eldenmoon pushed a commit to branch branch-3.0 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.0 by this push: new 7e94cc80e51 [fix](array_apply) array_apply replace logFatal with throw exception (#39902) 7e94cc80e51 is described below commit 7e94cc80e51c70eb7495f1b008355184d70b8f02 Author: amory <wangqian...@selectdb.com> AuthorDate: Tue Aug 27 10:18:31 2024 +0800 [fix](array_apply) array_apply replace logFatal with throw exception (#39902) backport #39105 --- .../vec/functions/array/function_array_apply.cpp | 87 +++++++++++----------- .../expressions/functions/scalar/ArrayApply.java | 10 +++ .../nereids_function_p0/scalar_function/Array.out | 3 + .../test_array_functions_by_literal.out | 3 + .../scalar_function/Array.groovy | 10 ++- .../test_array_functions_by_literal.groovy | 8 ++ 6 files changed, 78 insertions(+), 43 deletions(-) diff --git a/be/src/vec/functions/array/function_array_apply.cpp b/be/src/vec/functions/array/function_array_apply.cpp index 2ad680635a7..426347c449b 100644 --- a/be/src/vec/functions/array/function_array_apply.cpp +++ b/be/src/vec/functions/array/function_array_apply.cpp @@ -173,48 +173,51 @@ private: } // need exception safety -#define APPLY_ALL_TYPES(src_column, src_offsets, OP, cmp, dst) \ - do { \ - WhichDataType which(remove_nullable(nested_type)); \ - if (which.is_uint8()) { \ - *dst = _apply_internal<UInt8, OP>(src_column, src_offsets, cmp); \ - } else if (which.is_int8()) { \ - *dst = _apply_internal<Int8, OP>(src_column, src_offsets, cmp); \ - } else if (which.is_int16()) { \ - *dst = _apply_internal<Int16, OP>(src_column, src_offsets, cmp); \ - } else if (which.is_int32()) { \ - *dst = _apply_internal<Int32, OP>(src_column, src_offsets, cmp); \ - } else if (which.is_int64()) { \ - *dst = _apply_internal<Int64, OP>(src_column, src_offsets, cmp); \ - } else if (which.is_int128()) { \ - *dst = _apply_internal<Int128, OP>(src_column, src_offsets, cmp); \ - } else if (which.is_float32()) { \ - *dst = _apply_internal<Float32, OP>(src_column, src_offsets, cmp); \ - } else if (which.is_float64()) { \ - *dst = _apply_internal<Float64, OP>(src_column, src_offsets, cmp); \ - } else if (which.is_date()) { \ - *dst = _apply_internal<Int64, OP>(src_column, src_offsets, cmp); \ - } else if (which.is_date_time()) { \ - *dst = _apply_internal<Int64, OP>(src_column, src_offsets, cmp); \ - } else if (which.is_date_v2()) { \ - *dst = _apply_internal<UInt32, OP>(src_column, src_offsets, cmp); \ - } else if (which.is_date_time_v2()) { \ - *dst = _apply_internal<UInt64, OP>(src_column, src_offsets, cmp); \ - } else if (which.is_date_time_v2()) { \ - *dst = _apply_internal<UInt64, OP>(src_column, src_offsets, cmp); \ - } else if (which.is_decimal32()) { \ - *dst = _apply_internal<Decimal32, OP>(src_column, src_offsets, cmp); \ - } else if (which.is_decimal64()) { \ - *dst = _apply_internal<Decimal64, OP>(src_column, src_offsets, cmp); \ - } else if (which.is_decimal128v2()) { \ - *dst = _apply_internal<Decimal128V2, OP>(src_column, src_offsets, cmp); \ - } else if (which.is_decimal128v3()) { \ - *dst = _apply_internal<Decimal128V3, OP>(src_column, src_offsets, cmp); \ - } else if (which.is_decimal256()) { \ - *dst = _apply_internal<Decimal256, OP>(src_column, src_offsets, cmp); \ - } else { \ - LOG(FATAL) << "unsupported type " << nested_type->get_name(); \ - } \ +#define APPLY_ALL_TYPES(src_column, src_offsets, OP, cmp, dst) \ + do { \ + WhichDataType which(remove_nullable(nested_type)); \ + if (which.is_uint8()) { \ + *dst = _apply_internal<UInt8, OP>(src_column, src_offsets, cmp); \ + } else if (which.is_int8()) { \ + *dst = _apply_internal<Int8, OP>(src_column, src_offsets, cmp); \ + } else if (which.is_int16()) { \ + *dst = _apply_internal<Int16, OP>(src_column, src_offsets, cmp); \ + } else if (which.is_int32()) { \ + *dst = _apply_internal<Int32, OP>(src_column, src_offsets, cmp); \ + } else if (which.is_int64()) { \ + *dst = _apply_internal<Int64, OP>(src_column, src_offsets, cmp); \ + } else if (which.is_int128()) { \ + *dst = _apply_internal<Int128, OP>(src_column, src_offsets, cmp); \ + } else if (which.is_float32()) { \ + *dst = _apply_internal<Float32, OP>(src_column, src_offsets, cmp); \ + } else if (which.is_float64()) { \ + *dst = _apply_internal<Float64, OP>(src_column, src_offsets, cmp); \ + } else if (which.is_date()) { \ + *dst = _apply_internal<Int64, OP>(src_column, src_offsets, cmp); \ + } else if (which.is_date_time()) { \ + *dst = _apply_internal<Int64, OP>(src_column, src_offsets, cmp); \ + } else if (which.is_date_v2()) { \ + *dst = _apply_internal<UInt32, OP>(src_column, src_offsets, cmp); \ + } else if (which.is_date_time_v2()) { \ + *dst = _apply_internal<UInt64, OP>(src_column, src_offsets, cmp); \ + } else if (which.is_date_time_v2()) { \ + *dst = _apply_internal<UInt64, OP>(src_column, src_offsets, cmp); \ + } else if (which.is_decimal32()) { \ + *dst = _apply_internal<Decimal32, OP>(src_column, src_offsets, cmp); \ + } else if (which.is_decimal64()) { \ + *dst = _apply_internal<Decimal64, OP>(src_column, src_offsets, cmp); \ + } else if (which.is_decimal128v2()) { \ + *dst = _apply_internal<Decimal128V2, OP>(src_column, src_offsets, cmp); \ + } else if (which.is_decimal128v3()) { \ + *dst = _apply_internal<Decimal128V3, OP>(src_column, src_offsets, cmp); \ + } else if (which.is_decimal256()) { \ + *dst = _apply_internal<Decimal256, OP>(src_column, src_offsets, cmp); \ + } else { \ + throw doris::Exception(ErrorCode::INVALID_ARGUMENT, \ + "array_apply only accept array with nested type which is " \ + "uint/int/decimal/float/date but got : " + \ + nested_type->get_name()); \ + } \ } while (0) // need exception safety diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayApply.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayApply.java index 82bad4e4868..07e4c16d776 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayApply.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/scalar/ArrayApply.java @@ -26,6 +26,7 @@ import org.apache.doris.nereids.trees.expressions.literal.StringLikeLiteral; import org.apache.doris.nereids.trees.expressions.shape.BinaryExpression; import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor; import org.apache.doris.nereids.types.ArrayType; +import org.apache.doris.nereids.types.DataType; import org.apache.doris.nereids.types.VarcharType; import org.apache.doris.nereids.types.coercion.AnyDataType; import org.apache.doris.nereids.types.coercion.FollowToAnyDataType; @@ -67,6 +68,15 @@ public class ArrayApply extends ScalarFunction } } + @Override + public void checkLegalityBeforeTypeCoercion() { + DataType argType = ((ArrayType) child(0).getDataType()).getItemType(); + if (!(argType.isIntegralType() || argType.isFloatLikeType() || argType.isDecimalLikeType() + || argType.isDateLikeType() || argType.isBooleanType())) { + throw new AnalysisException("array_apply does not support type: " + toSql()); + } + } + @Override public ArrayApply withChildren(List<Expression> children) { Preconditions.checkArgument(children.size() == 3, diff --git a/regression-test/data/nereids_function_p0/scalar_function/Array.out b/regression-test/data/nereids_function_p0/scalar_function/Array.out index bc99cd9c386..17e8db9a68d 100644 --- a/regression-test/data/nereids_function_p0/scalar_function/Array.out +++ b/regression-test/data/nereids_function_p0/scalar_function/Array.out @@ -14451,3 +14451,6 @@ true -- !array_empty_be -- [] +-- !sql_array_map -- +[1, 1, 1, 1] + diff --git a/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions_by_literal.out b/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions_by_literal.out index 6f3b1756d48..bddcebea700 100644 --- a/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions_by_literal.out +++ b/regression-test/data/query_p0/sql_functions/array_functions/test_array_functions_by_literal.out @@ -977,3 +977,6 @@ _ -- !sql -- [11.9999, 34.0000] +-- !sql_array_map -- +[1, 1, 1, 1] + diff --git a/regression-test/suites/nereids_function_p0/scalar_function/Array.groovy b/regression-test/suites/nereids_function_p0/scalar_function/Array.groovy index e4e5b6eb7a2..dc97d10945d 100644 --- a/regression-test/suites/nereids_function_p0/scalar_function/Array.groovy +++ b/regression-test/suites/nereids_function_p0/scalar_function/Array.groovy @@ -1311,7 +1311,6 @@ suite("nereids_scalar_fn_Array") { sql """ set debug_skip_fold_constant=true; """ qt_array_empty_be """select array()""" - // array_min/max with nested array for args test { sql "select array_min(array(1,2,3),array(4,5,6));" check{result, exception, startTime, endTime -> @@ -1341,4 +1340,13 @@ suite("nereids_scalar_fn_Array") { logger.info(exception.message) } } + // array_map with string is can be succeed + qt_sql_array_map """select array_map(x->x!='', split_by_string('amory,is,better,committing', ','))""" + + // array_apply with string should be failed + test { + sql """select array_apply(split_by_string("amory,is,better,committing", ","), '!=', '');""" + exception("errCode = 2") + } + } diff --git a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy index fd372dfbd03..afc88acd651 100644 --- a/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy +++ b/regression-test/suites/query_p0/sql_functions/array_functions/test_array_functions_by_literal.groovy @@ -442,4 +442,12 @@ suite("test_array_functions_by_literal") { } } + // array_map with string is can be succeed + qt_sql_array_map """ select array_map(x->x!='', split_by_string('amory,is,better,committing', ',')) """ + + // array_apply with string should be failed + test { + sql """select array_apply(split_by_string("amory,is,better,committing", ","), '!=', '');""" + exception("No matching function") + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org