Skip to content

Commit

Permalink
[pick](array-funcs)fix array with empty arg in be behavior (#38708)
Browse files Browse the repository at this point in the history
## Proposed changes
backport: #36845
Issue Number: close #xxx

<!--Describe your changes.-->
  • Loading branch information
amorynan authored Aug 5, 2024
1 parent 1b3d4b4 commit 2653087
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
10 changes: 7 additions & 3 deletions be/src/vec/functions/array/function_array_constructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -59,11 +60,14 @@ class FunctionArrayConstructor : public IFunction {

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])));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
["2012-03-12 12:11:12", "2012-03-12 12:11:23"]

-- !array_empty_fe --
[]

-- !array_empty_be --
[]

Original file line number Diff line number Diff line change
Expand Up @@ -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;"
Expand All @@ -1305,5 +1308,4 @@ suite("nereids_scalar_fn_Array") {
logger.info(exception.message)
}
}

}

0 comments on commit 2653087

Please sign in to comment.