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

Backport #46995 to 23.2: Allow IPv4 in range() #47022

Merged
merged 1 commit into from
Mar 1, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/Functions/array/range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,19 @@ class FunctionRange : public IFunction
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);
}

Expand Down
3 changes: 3 additions & 0 deletions tests/queries/0_stateless/02674_range_ipv4.reference
Original file line number Diff line number Diff line change
@@ -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]
3 changes: 3 additions & 0 deletions tests/queries/0_stateless/02674_range_ipv4.sql
Original file line number Diff line number Diff line change
@@ -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);