Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pick](array-funcs)fix array with empty arg in be behavior #38708

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}

}
Loading