Allow to use concat with a single argument

This commit is contained in:
slvrtrn 2023-11-20 16:17:31 +01:00
parent 0eaf83b02e
commit 59c251bf88
3 changed files with 8 additions and 3 deletions

View File

@ -207,6 +207,8 @@ public:
FunctionBasePtr buildImpl(const ColumnsWithTypeAndName & arguments, const DataTypePtr & return_type) const override
{
if (arguments.size() == 1)
return FunctionFactory::instance().getImpl("toString", context)->build(arguments);
if (std::ranges::all_of(arguments, [](const auto & elem) { return isArray(elem.type); }))
return FunctionFactory::instance().getImpl("arrayConcat", context)->build(arguments);
if (std::ranges::all_of(arguments, [](const auto & elem) { return isMap(elem.type); }))
@ -221,10 +223,10 @@ public:
DataTypePtr getReturnTypeImpl(const DataTypes & arguments) const override
{
if (arguments.size() < 2)
if (arguments.empty())
throw Exception(
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH,
"Number of arguments for function {} doesn't match: passed {}, should be at least 2.",
"Number of arguments for function {} doesn't match: passed {}, should be at least 1.",
getName(),
arguments.size());

View File

@ -64,4 +64,6 @@ Three arguments test
42144255
42144
42144255
42
foo
Testing the alias

View File

@ -82,8 +82,9 @@ SELECT concat(materialize(42 :: Int32), materialize(144 :: UInt64));
SELECT concat(materialize(42 :: Int32), materialize(144 :: UInt64), materialize(255 :: UInt32));
SELECT concat(42, 144);
SELECT concat(42, 144, 255);
SELECT concat(42);
SELECT concat('foo');
SELECT CONCAT('Testing the ', 'alias');
SELECT concat(); -- { serverError 42 }
SELECT concat(1); -- { serverError 42 }