Skip to content

Commit

Permalink
[fix](array)fix array with empty arg in be behavior (#36845)
Browse files Browse the repository at this point in the history
  • Loading branch information
amorynan authored Jun 26, 2024
1 parent c46816a commit f0b7422
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 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.empty())
<< "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 @@ -14445,3 +14445,9 @@ true
["2012-03-11 11:10:11", "2012-03-11 11:10:21"]
["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 @@ -1276,4 +1276,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()"""
sql """ set debug_skip_fold_constant=true; """
qt_array_empty_be """select array()"""
}

0 comments on commit f0b7422

Please sign in to comment.