@@ -32,7 +32,7 @@ CREATE TABLE network_traffic (
3232 `time` TIMESTAMP DEFAULT 0,
3333 source_ip STRING,
3434 dest_ip STRING,
35- bytes_sent UINT64,
35+ bytes_sent UINT64,
3636 PRIMARY KEY(`id`),
3737 TIME INDEX(`time`)
3838);
@@ -78,9 +78,9 @@ Affected Rows: 8
7878
7979-- Test IPv4 string/number conversion functions
8080-- SQLNESS SORT_RESULT 3 1
81- SELECT
82- `id`,
83- ip_addr,
81+ SELECT
82+ `id`,
83+ ip_addr,
8484 ip_numeric,
8585 ipv4_string_to_num(ip_addr) AS computed_numeric,
8686 ipv4_num_to_string(ip_numeric) AS computed_addr
@@ -99,9 +99,32 @@ FROM ip_v4_data;
9999| 8 | 0.0.0.0 | 0 | 0 | 0.0.0.0 |
100100+----+-----------------+------------+------------------+-----------------+
101101
102+ -- Test IPv4 string/number conversion functions, by the function alias
103+ -- SQLNESS SORT_RESULT 3 1
104+ SELECT
105+ `id`,
106+ ip_addr,
107+ ip_numeric,
108+ ipv4_string_to_num(ip_addr) AS computed_numeric,
109+ inet_ntoa(ip_numeric) AS computed_addr
110+ FROM ip_v4_data;
111+
112+ +----+-----------------+------------+------------------+-----------------+
113+ | id | ip_addr | ip_numeric | computed_numeric | computed_addr |
114+ +----+-----------------+------------+------------------+-----------------+
115+ | 1 | 192.168.1.1 | 3232235777 | 3232235777 | 192.168.1.1 |
116+ | 2 | 10.0.0.1 | 167772161 | 167772161 | 10.0.0.1 |
117+ | 3 | 172.16.0.1 | 2886729729 | 2886729729 | 172.16.0.1 |
118+ | 4 | 127.0.0.1 | 2130706433 | 2130706433 | 127.0.0.1 |
119+ | 5 | 8.8.8.8 | 134744072 | 134744072 | 8.8.8.8 |
120+ | 6 | 192.168.0.1 | 3232235521 | 3232235521 | 192.168.0.1 |
121+ | 7 | 255.255.255.255 | 4294967295 | 4294967295 | 255.255.255.255 |
122+ | 8 | 0.0.0.0 | 0 | 0 | 0.0.0.0 |
123+ +----+-----------------+------------+------------------+-----------------+
124+
102125-- Test IPv4 CIDR functions
103126-- SQLNESS SORT_RESULT 3 1
104- SELECT
127+ SELECT
105128 `id`,
106129 ip_addr,
107130 subnet_mask,
@@ -126,7 +149,7 @@ FROM ip_v4_data;
126149-- Test IPv4 range checks
127150-- SQLNESS SORT_RESULT 3 1
128151-- Only get IPv4 records
129- SELECT
152+ SELECT
130153 t.`id`,
131154 t.source_ip,
132155 t.dest_ip,
@@ -159,9 +182,9 @@ WHERE t.source_ip NOT LIKE '%:%';
159182
160183-- Test IPv6 string/hex conversion functions
161184-- SQLNESS SORT_RESULT 3 1
162- SELECT
163- `id`,
164- ip_addr,
185+ SELECT
186+ `id`,
187+ ip_addr,
165188 ip_hex,
166189 ipv6_num_to_string(ip_hex) AS computed_addr
167190FROM ip_v6_data;
@@ -179,7 +202,7 @@ FROM ip_v6_data;
179202
180203-- Test IPv6 CIDR functions
181204-- SQLNESS SORT_RESULT 3 1
182- SELECT
205+ SELECT
183206 `id`,
184207 ip_addr,
185208 subnet_mask,
@@ -202,7 +225,7 @@ FROM ip_v6_data;
202225-- Test IPv6 range checks
203226-- SQLNESS SORT_RESULT 3 1
204227-- Only get IPv6 records
205- SELECT
228+ SELECT
206229 t.`id`,
207230 t.source_ip,
208231 t.dest_ip,
@@ -227,14 +250,14 @@ WHERE t.source_ip LIKE '%:%';
227250-- Combined IPv4/IPv6 example - Security analysis
228251-- Find all traffic from the same network to specific IPs
229252-- SQLNESS SORT_RESULT 3 1
230- SELECT
253+ SELECT
231254 source_ip,
232255 dest_ip,
233256 bytes_sent,
234- CASE
235- WHEN source_ip LIKE '%:%' THEN
257+ CASE
258+ WHEN source_ip LIKE '%:%' THEN
236259 ipv6_to_cidr(source_ip, arrow_cast(64, 'UInt8'))
237- ELSE
260+ ELSE
238261 ipv4_to_cidr(source_ip, arrow_cast(24, 'UInt8'))
239262 END AS source_network,
240263 CASE
@@ -261,7 +284,7 @@ ORDER BY bytes_sent DESC;
261284
262285-- Subnet analysis - IPv4
263286-- SQLNESS SORT_RESULT 3 1
264- SELECT
287+ SELECT
265288 ipv4_to_cidr(source_ip, arrow_cast(24,'UInt8')) AS subnet,
266289 COUNT(*) AS device_count,
267290 SUM(bytes_sent) AS total_bytes
@@ -280,7 +303,7 @@ ORDER BY total_bytes DESC;
280303
281304-- Subnet analysis - IPv6
282305-- SQLNESS SORT_RESULT 3 1
283- SELECT
306+ SELECT
284307 ipv6_to_cidr(source_ip, arrow_cast(48,'UInt8')) AS subnet,
285308 COUNT(*) AS device_count,
286309 SUM(bytes_sent) AS total_bytes
0 commit comments