mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-30 11:32:03 +00:00
Merge pull request #54212 from bharatnc/ncb/fix-ipv4-select
fix possible type mismatch with IPv4
This commit is contained in:
commit
15cb333eba
@ -870,7 +870,7 @@ NearestFieldType<std::decay_t<T>> & Field::get()
|
||||
// Disregard signedness when converting between int64 types.
|
||||
constexpr Field::Types::Which target = TypeToEnum<StoredType>::value;
|
||||
if (target != which
|
||||
&& (!isInt64OrUInt64orBoolFieldType(target) || !isInt64OrUInt64orBoolFieldType(which)))
|
||||
&& (!isInt64OrUInt64orBoolFieldType(target) || !isInt64OrUInt64orBoolFieldType(which)) && target != Field::Types::IPv4)
|
||||
throw Exception(ErrorCodes::LOGICAL_ERROR,
|
||||
"Invalid Field get from type {} to type {}", which, target);
|
||||
#endif
|
||||
|
@ -283,6 +283,11 @@ Field convertFieldToTypeImpl(const Field & src, const IDataType & type, const ID
|
||||
/// Already in needed type.
|
||||
return src;
|
||||
}
|
||||
if (which_type.isIPv4() && src.getType() == Field::Types::UInt64)
|
||||
{
|
||||
/// convert to UInt32 which is the underlying type for native IPv4
|
||||
return convertNumericType<UInt32>(src, type);
|
||||
}
|
||||
}
|
||||
else if (which_type.isUUID() && src.getType() == Field::Types::UUID)
|
||||
{
|
||||
|
@ -0,0 +1,8 @@
|
||||
1.1.1.1
|
||||
8.8.8.8
|
||||
1
|
||||
0
|
||||
1
|
||||
0
|
||||
0
|
||||
1
|
14
tests/queries/0_stateless/02864_test_ipv4_type_mismatch.sql
Normal file
14
tests/queries/0_stateless/02864_test_ipv4_type_mismatch.sql
Normal file
@ -0,0 +1,14 @@
|
||||
DROP TABLE IF EXISTS test;
|
||||
|
||||
CREATE TABLE test
|
||||
(
|
||||
ip IPv4 Codec(ZSTD(6)),
|
||||
) ENGINE MergeTree() order by ip;
|
||||
|
||||
INSERT INTO test values ('1.1.1.1');
|
||||
INSERT INTO test values (toIPv4('8.8.8.8'));
|
||||
|
||||
SELECT * FROM test ORDER BY ip;
|
||||
SELECT ip IN IPv4StringToNum('1.1.1.1') FROM test order by ip;
|
||||
SELECT ip IN ('1.1.1.1') FROM test order by ip;
|
||||
SELECT ip IN IPv4StringToNum('8.8.8.8') FROM test order by ip;
|
Loading…
Reference in New Issue
Block a user