Merge pull request #54212 from bharatnc/ncb/fix-ipv4-select

fix possible type mismatch with IPv4
This commit is contained in:
Anton Popov 2023-09-04 11:39:23 +02:00 committed by GitHub
commit 15cb333eba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 1 deletions

View File

@ -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

View File

@ -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)
{

View File

@ -0,0 +1,8 @@
1.1.1.1
8.8.8.8
1
0
1
0
0
1

View 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;