ClickHouse/ClickHouse

Add function to check if an IPv4/6 is in a list of subnets

Open

#6,808 opened on Sep 3, 2019

View on GitHub
 (4 comments) (3 reactions) (0 assignees)C++ (8,400 forks)batch import
featurehelp wanted

Repository metrics

Stars
 (47,419 stars)
PR merge metrics
 (Avg merge 2d 2h) (1,000 merged PRs in 30d)

Description

Use case Using ip_trie, I can check if an IP is in any X subnets I have no easy way to do a quick CLI query to match ~ 5 subnets without creating a dict

Describe the solution you'd like Something like IPmatchNet(ip, [subnet1, subnet2]) ip being IPv4 or IPv6 or UInt32 or FixedString(16) subnet1 is an IPv6 or IPv4 subnet as string (192.168.0.0/21), same as what is accepted by ip_trie

IPmatchNet should return the matched subnet so we can use it in GROUP BY Also IPmatchNet should handle IPv4 mapped IPv6 (#6806)

Additional context I'm bad at naming, IPmatchNet is just an exemple Right now cutIPv6 cuts bytes and not bits, so I can only use it for /24 /16 /8 (for IPv4)

Contributor guide