mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 09:32:06 +00:00
Fix cast into IPv4, IPv6 address in IN section
This commit is contained in:
parent
f6d9687174
commit
ff2d5dae83
@ -3506,9 +3506,13 @@ private:
|
||||
/// 'requested_result_is_nullable' is true if CAST to Nullable type is requested.
|
||||
WrapperType prepareImpl(const DataTypePtr & from_type, const DataTypePtr & to_type, bool requested_result_is_nullable) const
|
||||
{
|
||||
bool convert_to_ipv6 = to_type->getCustomName() && to_type->getCustomName()->getName() == "IPv6";
|
||||
/// We can cast IPv6 into IPv6, IPv4 into IPv4, but we should not allow to cast FixedString(16) into IPv6 as part of identity cast
|
||||
bool safe_convert_into_custom_type = true;
|
||||
|
||||
if (from_type->equals(*to_type) && !convert_to_ipv6)
|
||||
if (const auto * to_type_custom_name = to_type->getCustomName())
|
||||
safe_convert_into_custom_type = from_type->getCustomName() && from_type->getCustomName()->getName() == to_type_custom_name->getName();
|
||||
|
||||
if (from_type->equals(*to_type) && safe_convert_into_custom_type)
|
||||
{
|
||||
if (isUInt8(from_type))
|
||||
return createUInt8ToUInt8Wrapper(from_type, to_type);
|
||||
|
2
tests/queries/0_stateless/02243_in_ip_address.reference
Normal file
2
tests/queries/0_stateless/02243_in_ip_address.reference
Normal file
@ -0,0 +1,2 @@
|
||||
0
|
||||
0
|
9
tests/queries/0_stateless/02243_in_ip_address.sql
Normal file
9
tests/queries/0_stateless/02243_in_ip_address.sql
Normal file
@ -0,0 +1,9 @@
|
||||
DROP TABLE IF EXISTS test_table;
|
||||
CREATE TABLE test_table (id UInt64, value_ipv4 IPv4, value_ipv6 IPv6) ENGINE=MergeTree ORDER BY id;
|
||||
|
||||
INSERT INTO test_table VALUES (0, '127.0.0.1', '127.0.0.1');
|
||||
|
||||
SELECT id FROM test_table WHERE value_ipv4 IN (SELECT value_ipv4 FROM test_table);
|
||||
SELECT id FROM test_table WHERE value_ipv6 IN (SELECT value_ipv6 FROM test_table);
|
||||
|
||||
DROP TABLE test_table;
|
Loading…
Reference in New Issue
Block a user