Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport #45865 to 23.1: Allow implicit narrowing conversion UInt64 => IPv4 #46967

Merged
merged 1 commit into from
Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Functions/FunctionsConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ struct ConvertImpl
}
else if constexpr (
(std::is_same_v<FromDataType, DataTypeIPv4> != std::is_same_v<ToDataType, DataTypeIPv4>)
&& !(is_any_of<FromDataType, DataTypeUInt8, DataTypeUInt16, DataTypeUInt32> || is_any_of<ToDataType, DataTypeUInt32, DataTypeUInt64, DataTypeUInt128, DataTypeUInt256>)
&& !(is_any_of<FromDataType, DataTypeUInt8, DataTypeUInt16, DataTypeUInt32, DataTypeUInt64> || is_any_of<ToDataType, DataTypeUInt32, DataTypeUInt64, DataTypeUInt128, DataTypeUInt256>)
)
{
throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Conversion from {} to {} is not supported",
Expand Down Expand Up @@ -303,7 +303,10 @@ struct ConvertImpl
}
else
{
vec_to[i] = static_cast<ToFieldType>(vec_from[i]);
if constexpr (std::is_same_v<ToDataType, DataTypeIPv4> && std::is_same_v<FromDataType, DataTypeUInt64>)
vec_to[i] = static_cast<ToFieldType>(static_cast<IPv4::UnderlyingType>(vec_from[i]));
else
vec_to[i] = static_cast<ToFieldType>(vec_from[i]);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
85.85.85.85
138.68.230.86
4 changes: 4 additions & 0 deletions tests/queries/0_stateless/02551_ipv4_implicit_uint64.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE TABLE ip4test (ip IPv4) ENGINE=Memory;
INSERT INTO ip4test VALUES (22906492245), (2319771222);
SELECT * FROM ip4test;
DROP TABLE ip4test;