2017-04-01 09:19:00 +00:00
|
|
|
#include <Functions/FunctionFactory.h>
|
|
|
|
#include <Functions/FunctionsStringArray.h>
|
2019-12-29 01:13:17 +00:00
|
|
|
|
2021-10-12 21:23:40 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
bool isNullableStringOrNullableNothing(DB::DataTypePtr type)
|
|
|
|
{
|
|
|
|
if (type->isNullable())
|
|
|
|
{
|
|
|
|
const auto & nested_type = assert_cast<const DB::DataTypeNullable &>(*type).getNestedType();
|
|
|
|
if (isString(nested_type) || isNothing(nested_type))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2014-08-22 00:57:20 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2021-10-12 21:23:40 +00:00
|
|
|
DataTypePtr FunctionArrayStringConcat::getReturnTypeImpl(const DataTypes & arguments) const
|
|
|
|
{
|
|
|
|
if (arguments.size() != 1 && arguments.size() != 2)
|
|
|
|
throw Exception(
|
|
|
|
"Number of arguments for function " + getName() + " doesn't match: passed " + toString(arguments.size())
|
|
|
|
+ ", should be 1 or 2.",
|
|
|
|
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
|
|
|
|
|
|
|
const DataTypeArray * array_type = checkAndGetDataType<DataTypeArray>(arguments[0].get());
|
|
|
|
// An array consisting of only Null-s has type Array(Nullable(Nothing))
|
|
|
|
if (!array_type || !(isString(array_type->getNestedType()) || isNullableStringOrNullableNothing(array_type->getNestedType())))
|
|
|
|
throw Exception(
|
|
|
|
"First argument for function " + getName() + " must be an array of String-s or Nullable(String)-s.",
|
|
|
|
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
|
|
|
|
|
|
|
if (arguments.size() == 2 && !isString(arguments[1]))
|
|
|
|
throw Exception("Second argument for function " + getName() + " must be constant string.", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
|
|
|
|
|
|
|
return std::make_shared<DataTypeString>();
|
|
|
|
}
|
2014-08-22 00:57:20 +00:00
|
|
|
|
|
|
|
void registerFunctionsStringArray(FunctionFactory & factory)
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
factory.registerFunction<FunctionExtractAll>();
|
|
|
|
factory.registerFunction<FunctionAlphaTokens>();
|
2021-06-19 12:33:36 +00:00
|
|
|
factory.registerFunction<FunctionSplitByNonAlpha>();
|
|
|
|
factory.registerFunction<FunctionSplitByWhitespace>();
|
2017-04-01 07:20:54 +00:00
|
|
|
factory.registerFunction<FunctionSplitByChar>();
|
|
|
|
factory.registerFunction<FunctionSplitByString>();
|
2021-05-13 02:37:09 +00:00
|
|
|
factory.registerFunction<FunctionSplitByRegexp>();
|
2017-04-01 07:20:54 +00:00
|
|
|
factory.registerFunction<FunctionArrayStringConcat>();
|
2014-08-22 00:57:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|