Skip to content

Commit 96bc928

Browse files
author
Vadim Averin
authored
Cherry-pick IP UDF changes from main (#618 #981) (#2465)
1 parent 2b011a8 commit 96bc928

File tree

12 files changed

+612
-54
lines changed

12 files changed

+612
-54
lines changed

ydb/docs/en/core/yql/reference/yql-core/udf/list/ip.md

+19
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@ The `Ip` module supports both the IPv4 and IPv6 addresses. By default, they are
55
**List of functions**
66

77
* ```Ip::FromString(String{Flags:AutoMap}) -> String?``` - From a human-readable representation to a binary representation.
8+
* ```Ip::SubnetFromString(String{Flags:AutoMap}) -> String?``` - From a human-readable representation of subnet to a binary representation.
89
* ```Ip::ToString(String{Flags:AutoMap}) -> String?``` - From a binary representation to a human-readable representation.
10+
* ```Ip::SubnetToString(String{Flags:AutoMap}) -> String?``` - From a binary representation of subnet to a human-readable representation.
911
* ```Ip::IsIPv4(String?) -> Bool```
1012
* ```Ip::IsIPv6(String?) -> Bool```
1113
* ```Ip::IsEmbeddedIPv4(String?) -> Bool```
1214
* ```Ip::ConvertToIPv6(String{Flags:AutoMap}) -> String```: IPv6 remains unchanged, and IPv4 becomes embedded in IPv6
1315
* ```Ip::GetSubnet(String{Flags:AutoMap}, [Uint8?]) -> String```: The second argument is the subnet size, by default it's 24 for IPv4 and 64 for IPv6
16+
* ```Ip::GetSubnetByMask(String{Flags:AutoMap}, String{Flags:AutoMap}) -> String```: The first argument is the base address, the second argument is the bit mask of a desired subnet.
17+
* ```Ip::SubnetMatch(String{Flags:AutoMap}, String{Flags:AutoMap}) -> Bool```: The first argument is a subnet, the second argument is a subnet or an address.
18+
1419

1520
**Examples**
1621

@@ -25,5 +30,19 @@ SELECT
2530
Ip::FromString("213.180.193.3")
2631
)
2732
); -- "213.180.193.0"
33+
34+
SELECT
35+
Ip::SubnetMatch(
36+
Ip::SubnetFromString("192.168.0.1/16"),
37+
Ip::FromString("192.168.1.14"),
38+
); -- true
39+
40+
SELECT
41+
Ip::ToString(
42+
Ip::GetSubnetByMask(
43+
Ip::FromString("192.168.0.1"),
44+
Ip::FromString("255.255.0.0")
45+
)
46+
); -- "192.168.0.0"
2847
```
2948

ydb/docs/ru/core/yql/reference/yql-core/udf/list/ip.md

+18
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44
**Список функций**
55

66
* ```Ip::FromString(String{Flags:AutoMap}) -> String?``` - из человекочитаемого представления в бинарное
7+
* ```Ip::SubnetFromString(String{Flags:AutoMap}) -> String?``` - из человекочитаемого представления подсети в бинарное
78
* ```Ip::ToString(String{Flags:AutoMap}) -> String?``` - из бинарного представления в человекочитаемое
9+
* ```Ip::SubnetToString(String{Flags:AutoMap}) -> String?``` - из бинарного представления подсети в человекочитаемое
810
* ```Ip::IsIPv4(String?) -> Bool```
911
* ```Ip::IsIPv6(String?) -> Bool```
1012
* ```Ip::IsEmbeddedIPv4(String?) -> Bool```
1113
* ```Ip::ConvertToIPv6(String{Flags:AutoMap}) -> String``` - IPv6 остается без изменений, а IPv4 становится embedded в IPv6
1214
* ```Ip::GetSubnet(String{Flags:AutoMap}, [Uint8?]) -> String``` - во втором аргументе размер подсети, по умолчанию 24 для IPv4 и 64 для IPv6
15+
* ```Ip::GetSubnetByMask(String{Flags:AutoMap}, String{Flags:AutoMap}) -> String``` - во втором аргументе битовая маска подсети
16+
* ```Ip::SubnetMatch(String{Flags:AutoMap}, String{Flags:AutoMap}) -> Bool``` - в первом аргументе подсеть, во втором аргументе подсеть или адрес
1317

1418
**Примеры**
1519

@@ -24,4 +28,18 @@ SELECT
2428
Ip::FromString("213.180.193.3")
2529
)
2630
); -- "213.180.193.0"
31+
32+
SELECT
33+
Ip::SubnetMatch(
34+
Ip::SubnetFromString("192.168.0.1/16"),
35+
Ip::FromString("192.168.1.14"),
36+
); -- true
37+
38+
SELECT
39+
Ip::ToString(
40+
Ip::GetSubnetByMask(
41+
Ip::FromString("192.168.0.1"),
42+
Ip::FromString("255.255.0.0")
43+
)
44+
); -- "192.168.0.0"
2745
```

0 commit comments

Comments
 (0)