Skip to content

Commit

Permalink
Merge pull request ClickHouse#69576 from bigo-sg/arrayzip_allow_empty
Browse files Browse the repository at this point in the history
Allow empty arguments for arrayZip/arrayZipUnaligned
  • Loading branch information
alexkats authored Sep 17, 2024
2 parents cd7a1a9 + 7155302 commit 2cef99c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
17 changes: 8 additions & 9 deletions src/Functions/array/arrayZip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace ErrorCodes
{
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
extern const int SIZES_OF_ARRAYS_DONT_MATCH;
extern const int TOO_FEW_ARGUMENTS_FOR_FUNCTION;
extern const int ILLEGAL_COLUMN;
}

Expand All @@ -38,13 +37,6 @@ class FunctionArrayZip : public IFunction

DataTypePtr getReturnTypeImpl(const ColumnsWithTypeAndName & arguments) const override
{
if (arguments.empty())
throw Exception(
ErrorCodes::TOO_FEW_ARGUMENTS_FOR_FUNCTION,
"Function {} needs at least one argument; passed {}.",
getName(),
arguments.size());

DataTypes arguments_types;
for (size_t index = 0; index < arguments.size(); ++index)
{
Expand All @@ -68,9 +60,16 @@ class FunctionArrayZip : public IFunction
}

ColumnPtr
executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & /*result_type*/, size_t input_rows_count) const override
executeImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & result_type, size_t input_rows_count) const override
{
size_t num_arguments = arguments.size();
if (num_arguments == 0)
{
auto res_col = result_type->createColumn();
res_col->insertDefault();
return ColumnConst::create(std::move(res_col), input_rows_count);
}

Columns holders(num_arguments);
Columns tuple_columns(num_arguments);

Expand Down
1 change: 1 addition & 0 deletions tests/queries/0_stateless/01045_array_zip.reference
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[('a','d'),('b','e'),('c','f')]
[('a','d','g'),('b','e','h'),('c','f','i')]
[]
2 changes: 1 addition & 1 deletion tests/queries/0_stateless/01045_array_zip.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SELECT arrayZip(['a', 'b', 'c'], ['d', 'e', 'f']);

SELECT arrayZip(['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']);

SELECT arrayZip(); -- { serverError TOO_FEW_ARGUMENTS_FOR_FUNCTION }
SELECT arrayZip();

SELECT arrayZip('a', 'b', 'c'); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[('a','d'),('b','e'),('c','f')] Array(Tuple(Nullable(String), Nullable(String)))
[('a','d','g'),('b','e','h'),('c','f','i')]
[]
[('a','d'),('b','e'),('c','f'),(NULL,'g')]
[('a',1),(NULL,2),(NULL,3)]
[('a',1,1.1),('b',2,2.2),('c',NULL,3.3),(NULL,NULL,4.4)]
Expand Down
2 changes: 1 addition & 1 deletion tests/queries/0_stateless/03230_array_zip_unaligned.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ SELECT arrayZipUnaligned(['a', 'b', 'c'], ['d', 'e', 'f']) as x, toTypeName(x);

SELECT arrayZipUnaligned(['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']);

SELECT arrayZipUnaligned(); -- { serverError TOO_FEW_ARGUMENTS_FOR_FUNCTION }
SELECT arrayZipUnaligned();

SELECT arrayZipUnaligned('a', 'b', 'c'); -- { serverError ILLEGAL_TYPE_OF_ARGUMENT }

Expand Down

0 comments on commit 2cef99c

Please sign in to comment.