ClickHouse/dbms/tests/queries/0_stateless/00725_ipv4_ipv6_domains.sql
Vasily Nemkov 2716df8ab2 IPv4 and IPv6 Domain implementation.
Added:
 * IDataTypeDomain interface;
 * method DataTypeFactory::registerDataTypeDomain for registering domains;
 * DataTypeDomainWithSimpleSerialization domain base class with simple serialization/deserialization;
 * Concrete IPv4 and IPv6 domain implementations: DataTypeDomanIPv6 and DataTypeDomanIPv4;

Updated:
 * IDataType text serialization/deserialization methods;
 * IDataType implementation to use domain for text serialization/deserialization;
 * Refactored implementation of the IPv4/IPv6 functions to use formatIPv4/v6 and parseIPv4/v6 from Common/formatIPv6.h;

Tests:
 * Added test cases for IPv4 and IPv6 domains.
 * Updated IPv4/v6 functions tests to validate more cases;
 * Added performance tests for IPv4 and IPv6 related functions;
2019-02-04 12:37:46 +03:00

60 lines
1.9 KiB
SQL

DROP TABLE IF EXISTS test.ipv4_test;
-- Only valid values for IPv4
CREATE TABLE test.ipv4_test (ipv4_ IPv4) ENGINE = Memory;
-- ipv4_ column shoud have type 'IPv4'
SHOW CREATE TABLE test.ipv4_test;
INSERT INTO test.ipv4_test (ipv4_) VALUES ('0.0.0.0'), ('255.255.255.255'), ('192.168.0.91'), ('127.0.0.1'), ('8.8.8.8');
SELECT ipv4_, hex(ipv4_) FROM test.ipv4_test ORDER BY ipv4_;
SELECT '< 127.0.0.1', ipv4_ FROM test.ipv4_test
WHERE ipv4_ < toIPv4('127.0.0.1')
ORDER BY ipv4_;
SELECT '> 127.0.0.1', ipv4_ FROM test.ipv4_test
WHERE ipv4_ > toIPv4('127.0.0.1')
ORDER BY ipv4_;
SELECT '= 127.0.0.1', ipv4_ FROM test.ipv4_test
WHERE ipv4_ = toIPv4('127.0.0.1')
ORDER BY ipv4_;
-- TODO: Assert that invalid values can't be inserted into IPv4 column.
DROP TABLE IF EXISTS test.ipv4_test;
select 'euqality of IPv4-mapped IPv6 value and IPv4 promoted to IPv6 with function:', toIPv6('::ffff:127.0.0.1') = IPv4ToIPv6(toIPv4('127.0.0.1'));
DROP TABLE IF EXISTS test.ipv6_test;
-- Only valid values for IPv6
CREATE TABLE test.ipv6_test (ipv6_ IPv6) ENGINE = Memory;
-- ipv6_ column shoud have type 'IPv6'
SHOW CREATE TABLE test.ipv6_test;
INSERT INTO test.ipv6_test VALUES ('::'), ('0:0:0:0:0:0:0:0'), ('FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF'), ('2001:0DB8:AC10:FE01:FEED:BABE:CAFE:F00D'), ('0000:0000:0000:0000:0000:FFFF:C1FC:110A'), ('::ffff:127.0.0.1'), ('::ffff:8.8.8.8');
SELECT ipv6_, hex(ipv6_) FROM test.ipv6_test ORDER BY ipv6_;
SELECT '< 127.0.0.1', ipv6_ FROM test.ipv6_test
WHERE ipv6_ < IPv4ToIPv6(toIPv4('127.0.0.1'))
ORDER BY ipv6_;
SELECT '> 127.0.0.1', ipv6_ FROM test.ipv6_test
WHERE ipv6_ > IPv4ToIPv6(toIPv4('127.0.0.1'))
ORDER BY ipv6_;
SELECT '= 127.0.0.1', ipv6_ FROM test.ipv6_test
WHERE ipv6_ = IPv4ToIPv6(toIPv4('127.0.0.1'))
ORDER BY ipv6_;
-- TODO: Assert that invalid values can't be inserted into IPv6 column.
DROP TABLE IF EXISTS test.ipv6_test;