-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
Functions for calculate lower and high range of an IP address using a CIDR mask #5095
Functions for calculate lower and high range of an IP address using a CIDR mask #5095
Conversation
…unctions in english
Would it make sense to return an (IPv4,IPv4) tuple rather than a (UInt32,UInt32) tuple? That would make the interface more intuitive for display/interactive use. Specific use cases can always cast to UInt32 afterwards if needed. |
Thanks for the suggestion, now both function return a tuple with an IPv4 and IPv6! |
Need to remove |
IPv6CIDRtoIPv6Range -> IPv6CIDRToRange |
String getName() const override { return name; } | ||
|
||
size_t getNumberOfArguments() const override { return 2; } | ||
bool isInjective(const Block &) override { return true; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It isn't.
Missing performance test. |
I will fix all the remaining issues. |
I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en
For changelog. Remove if this is non-significant change.
Category (leave one):
Short description (up to few sentences):
Functions for calculate the lower range and an higher range for an IP using a CIDR, both for
IPv4
andIPv6
.Detailed description (optional):
This two functions, named
IPv4CIDRtoIPv4Range
andIPv6CIDRtoIPv6Range
take two arguments, an IP address (inIPv4
address for theIPv4
function, and inIPv6
addressfor
IPv6
function), and anUInt8
who correspond to the CIDR mask we want to apply.An equivalent of
IPv4CIDRtoIPv4Range(IPv4NumToString('192.168.0.0'), 16)
can be interpreted as192.168.0.0/16
using the CIDR notation.It return a tuple containing two
IPv4
for theIPv4
functions and a tuple containing twoIPv6
for theIPv6
, it contain for both the theorically the lowest and highest IP for the subnet.This function can potentially use to know if an IP is part of a subnet, and also if we use the lowest or highest range to aggregate the IP by subnet.
A possible solution was posted on issue #247 for an
IPv4
range (solution based also on the first post of the issue) using directly a query and using a bit shifting. But it wouldn't be possible for calculate anIPv6
subnet as Clickhouse storedIPv6
using aFixedString(16)
, who make the task a little bit difficult with doing a bit shifting on an array.