Merge pull request #46995 from ClickHouse/function-range-allow-ipv4

Allow IPv4 in range()
This commit is contained in:
Anton Popov 2023-02-28 14:32:24 +01:00 committed by GitHub
commit 7b9d54a2d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 4 deletions

View File

@ -55,14 +55,19 @@ private:
getName(), arguments.size());
}
for (const auto & arg : arguments)
DataTypes arg_types;
for (size_t i = 0, size = arguments.size(); i < size; ++i)
{
if (!isInteger(arg))
if (i < 2 && WhichDataType(arguments[i]).isIPv4())
arg_types.emplace_back(std::make_shared<DataTypeUInt32>());
else if (isInteger(arguments[i]))
arg_types.push_back(arguments[i]);
else
throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal type {} of argument of function {}",
arg->getName(), getName());
arguments[i]->getName(), getName());
}
DataTypePtr common_type = getLeastSupertype(arguments);
DataTypePtr common_type = getLeastSupertype(arg_types);
return std::make_shared<DataTypeArray>(common_type);
}

View File

@ -0,0 +1,3 @@
[2887712768,2887712769,2887712770,2887712771,2887712772,2887712773,2887712774,2887712775,2887712776,2887712777]
[2887712768,2887712769,2887712770,2887712771,2887712772,2887712773,2887712774,2887712775,2887712776,2887712777]
[2887712768,2887712769,2887712770,2887712771,2887712772,2887712773,2887712774,2887712775,2887712776,2887712777]

View File

@ -0,0 +1,3 @@
SELECT range(toIPv4('172.31.0.0'), toIPv4('172.31.0.10'));
SELECT range(2887712768, toIPv4('172.31.0.10'));
SELECT range(toIPv4('172.31.0.0'), 2887712778);