From f4a8b099de9f9ac9fe52ef32df85b4fb0b90cfc5 Mon Sep 17 00:00:00 2001 From: Yakov Olkhovskiy Date: Mon, 27 Feb 2023 21:36:21 +0000 Subject: [PATCH] allow IPv4 in range() --- src/Functions/array/range.cpp | 13 +++++++++---- .../queries/0_stateless/02674_range_ipv4.reference | 3 +++ tests/queries/0_stateless/02674_range_ipv4.sql | 3 +++ 3 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 tests/queries/0_stateless/02674_range_ipv4.reference create mode 100644 tests/queries/0_stateless/02674_range_ipv4.sql diff --git a/src/Functions/array/range.cpp b/src/Functions/array/range.cpp index dc09facb81b..f1f0fef8fd9 100644 --- a/src/Functions/array/range.cpp +++ b/src/Functions/array/range.cpp @@ -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()); + 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(common_type); } diff --git a/tests/queries/0_stateless/02674_range_ipv4.reference b/tests/queries/0_stateless/02674_range_ipv4.reference new file mode 100644 index 00000000000..76fc0c45bd3 --- /dev/null +++ b/tests/queries/0_stateless/02674_range_ipv4.reference @@ -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] diff --git a/tests/queries/0_stateless/02674_range_ipv4.sql b/tests/queries/0_stateless/02674_range_ipv4.sql new file mode 100644 index 00000000000..1241b727014 --- /dev/null +++ b/tests/queries/0_stateless/02674_range_ipv4.sql @@ -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);