This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new 2653087843b [pick](array-funcs)fix array with empty arg in be behavior
(#38708)
2653087843b is described below
commit 2653087843b63fd2152750fd84f284ef9a9eb3fc
Author: amory <[email protected]>
AuthorDate: Mon Aug 5 09:08:28 2024 +0800
[pick](array-funcs)fix array with empty arg in be behavior (#38708)
## Proposed changes
backport: https://github.com/apache/doris/pull/36845
Issue Number: close #xxx
<!--Describe your changes.-->
---
be/src/vec/functions/array/function_array_constructor.cpp | 10 +++++++---
.../data/nereids_function_p0/scalar_function/Array.out | 9 ++++++++-
.../suites/nereids_function_p0/scalar_function/Array.groovy | 4 +++-
3 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/be/src/vec/functions/array/function_array_constructor.cpp
b/be/src/vec/functions/array/function_array_constructor.cpp
index d19d29ec254..cec7e03b22e 100644
--- a/be/src/vec/functions/array/function_array_constructor.cpp
+++ b/be/src/vec/functions/array/function_array_constructor.cpp
@@ -36,6 +36,7 @@
#include "vec/data_types/data_type.h"
#include "vec/data_types/data_type_array.h"
#include "vec/data_types/data_type_nullable.h"
+#include "vec/data_types/data_type_number.h"
#include "vec/functions/function.h"
#include "vec/functions/simple_function_factory.h"
@@ -59,11 +60,14 @@ public:
bool use_default_implementation_for_nulls() const override { return false;
}
- size_t get_number_of_arguments() const override { return 1; }
+ size_t get_number_of_arguments() const override { return 0; }
DataTypePtr get_return_type_impl(const DataTypes& arguments) const
override {
- DCHECK(arguments.size() > 0)
- << "function: " << get_name() << ", arguments should not be
empty";
+ // we accept with empty argument, like array(), which will be treated
as array(UInt8)
+ if (arguments.empty()) {
+ return std::make_shared<DataTypeArray>(
+ make_nullable(std::make_shared<DataTypeUInt8>()));
+ }
return
std::make_shared<DataTypeArray>(make_nullable(remove_nullable(arguments[0])));
}
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 c6c32bf9b15..cfad441a499 100644
--- a/regression-test/data/nereids_function_p0/scalar_function/Array.out
+++ b/regression-test/data/nereids_function_p0/scalar_function/Array.out
@@ -14443,4 +14443,11 @@ true
["2012-03-09 09:08:09", "2012-03-09 09:08:17"]
["2012-03-10 10:09:10", "2012-03-10 10:09:19"]
["2012-03-11 11:10:11", "2012-03-11 11:10:21"]
-["2012-03-12 12:11:12", "2012-03-12 12:11:23"]
\ No newline at end of file
+["2012-03-12 12:11:12", "2012-03-12 12:11:23"]
+
+-- !array_empty_fe --
+[]
+
+-- !array_empty_be --
+[]
+
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 a6f4b0604c4..e1eb2bab515 100644
--- a/regression-test/suites/nereids_function_p0/scalar_function/Array.groovy
+++ b/regression-test/suites/nereids_function_p0/scalar_function/Array.groovy
@@ -1281,6 +1281,9 @@ suite("nereids_scalar_fn_Array") {
qt_sequence_datetime_hour """select sequence(kdtmv2s1, date_add(kdtmv2s1,
interval kint-3 hour), interval kint hour) from fn_test order by kdtmv2s1;"""
qt_sequence_datetime_minute """select sequence(kdtmv2s1,
date_add(kdtmv2s1, interval kint+1 minute), interval kint minute) from fn_test
order by kdtmv2s1;"""
qt_sequence_datetime_second """select sequence(kdtmv2s1,
date_add(kdtmv2s1, interval kint second), interval kint-1 second) from fn_test
order by kdtmv2s1;"""
+
+ // with array empty
+ qt_array_empty_fe """select array()"""
// make large error size
test {
sql "select array_size(sequence(kdtmv2s1, date_add(kdtmv2s1, interval
kint+1000 year), interval kint hour)) from fn_test order by kdtmv2s1;"
@@ -1305,5 +1308,4 @@ suite("nereids_scalar_fn_Array") {
logger.info(exception.message)
}
}
-
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]