-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat: Add support for UUID comparison functions #10791
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,5 +108,119 @@ TEST_F(UuidFunctionsTest, unsupportedCast) { | |
evaluate("cast(123 as uuid())", input), "Cannot cast BIGINT to UUID."); | ||
} | ||
|
||
TEST_F(UuidFunctionsTest, comparisons) { | ||
const auto uuidEval = [&](const std::optional<std::string>& lhs, | ||
const std::string& operation, | ||
const std::optional<std::string>& rhs) { | ||
return evaluateOnce<bool>( | ||
fmt::format("cast(c0 as uuid) {} cast(c1 as uuid)", operation), | ||
lhs, | ||
rhs); | ||
}; | ||
|
||
ASSERT_EQ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just confirming that you got the same results with Presto Java. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I've copied these values to the Presto Java UUID tests to run and get the same results. |
||
true, | ||
uuidEval( | ||
"33355449-2c7d-43d7-967a-f53cd23215ad", | ||
"<", | ||
"ffffffff-ffff-ffff-ffff-ffffffffffff")); | ||
ASSERT_EQ( | ||
aditi-pandit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
false, | ||
uuidEval( | ||
"33355449-2c7d-43d7-967a-f53cd23215ad", | ||
"<", | ||
"00000000-0000-0000-0000-000000000000")); | ||
ASSERT_EQ( | ||
true, | ||
uuidEval( | ||
"f768f36d-4f09-4da7-a298-3564d8f3c986", | ||
">", | ||
"00000000-0000-0000-0000-000000000000")); | ||
ASSERT_EQ( | ||
false, | ||
uuidEval( | ||
"f768f36d-4f09-4da7-a298-3564d8f3c986", | ||
">", | ||
"ffffffff-ffff-ffff-ffff-ffffffffffff")); | ||
|
||
ASSERT_EQ( | ||
true, | ||
uuidEval( | ||
"33355449-2c7d-43d7-967a-f53cd23215ad", | ||
"<=", | ||
"33355449-2c7d-43d7-967a-f53cd23215ad")); | ||
ASSERT_EQ( | ||
true, | ||
uuidEval( | ||
"33355449-2c7d-43d7-967a-f53cd23215ad", | ||
"<=", | ||
"ffffffff-ffff-ffff-ffff-ffffffffffff")); | ||
ASSERT_EQ( | ||
true, | ||
uuidEval( | ||
"33355449-2c7d-43d7-967a-f53cd23215ad", | ||
">=", | ||
"33355449-2c7d-43d7-967a-f53cd23215ad")); | ||
ASSERT_EQ( | ||
true, | ||
uuidEval( | ||
"ffffffff-ffff-ffff-ffff-ffffffffffff", | ||
">=", | ||
"33355449-2c7d-43d7-967a-f53cd23215ad")); | ||
|
||
ASSERT_EQ( | ||
true, | ||
uuidEval( | ||
"f768f36d-4f09-4da7-a298-3564d8f3c986", | ||
"==", | ||
"f768f36d-4f09-4da7-a298-3564d8f3c986")); | ||
ASSERT_EQ( | ||
true, | ||
uuidEval( | ||
"eed9f812-4b0c-472f-8a10-4ae7bff79a47", | ||
"!=", | ||
"f768f36d-4f09-4da7-a298-3564d8f3c986")); | ||
|
||
ASSERT_EQ( | ||
true, | ||
uuidEval( | ||
"11000000-0000-0022-0000-000000000000", | ||
"<", | ||
"22000000-0000-0011-0000-000000000000")); | ||
ASSERT_EQ( | ||
true, | ||
uuidEval( | ||
"00000000-0000-0000-2200-000000000011", | ||
">", | ||
"00000000-0000-0000-1100-000000000022")); | ||
ASSERT_EQ( | ||
false, | ||
uuidEval( | ||
"00000000-0000-0000-0000-000000000011", | ||
">", | ||
"22000000-0000-0000-0000-000000000000")); | ||
ASSERT_EQ( | ||
false, | ||
uuidEval( | ||
"11000000-0000-0000-0000-000000000000", | ||
"<", | ||
"00000000-0000-0000-0000-000000000022")); | ||
|
||
std::string lhs = "12342345-3456-4567-5678-678978908901"; | ||
std::string rhs = "23451234-4567-3456-6789-567889017890"; | ||
ASSERT_EQ(true, uuidEval(lhs, "<", rhs)); | ||
|
||
for (vector_size_t i = 0; i < lhs.size(); i++) { | ||
if (lhs[i] == '-') { | ||
continue; | ||
} | ||
lhs[i] = '0'; | ||
rhs[i] = '0'; | ||
bool expected = boost::lexical_cast<boost::uuids::uuid>(lhs) < | ||
boost::lexical_cast<boost::uuids::uuid>(rhs); | ||
ASSERT_EQ(expected, uuidEval(lhs, "<", rhs)); | ||
} | ||
} | ||
|
||
} // namespace | ||
} // namespace facebook::velox::functions::prestosql |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you try this version of evaluateOnce https://github.com/facebookincubator/velox/blob/main/velox/functions/prestosql/tests/utils/FunctionBaseTest.h#L241
that can override the logical type. It might reduce the casting in your expression then.
So the call would be something like
evaluateOnce<bool>(fmt::format("c0 {} c1", operation), {UUID(), UUID()}, lhs, rhs)
But of course that assumes that you are not relying on the casting to reshuffle bytes in a way that the uint128_t comparisons hold.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That does work, but then I would need to construct the UUIDs with boost and then convert to an int128_t to pass to the eval. I think the end result is less clear, and this way also tests the UUID casting.