From 918598f19e58a16c69ce580ecde933bbf020a7b8 Mon Sep 17 00:00:00 2001 From: Bryan Cutler Date: Sun, 22 Sep 2024 17:01:43 -0700 Subject: [PATCH] Cleanup test to use evaluateOnce --- .../prestosql/tests/UuidFunctionsTest.cpp | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/velox/functions/prestosql/tests/UuidFunctionsTest.cpp b/velox/functions/prestosql/tests/UuidFunctionsTest.cpp index c11b81964dba2..0043a7847facd 100644 --- a/velox/functions/prestosql/tests/UuidFunctionsTest.cpp +++ b/velox/functions/prestosql/tests/UuidFunctionsTest.cpp @@ -109,6 +109,53 @@ TEST_F(UuidFunctionsTest, unsupportedCast) { } TEST_F(UuidFunctionsTest, comparisons) { + const auto uuidEval = [&](const std::optional& lhs, const std::string& operation, const std::optional& rhs) { + return evaluateOnce(fmt::format("cast(c0 as uuid) {} cast(c1 as uuid)", operation), lhs, rhs); + }; + /*const auto uuidComparison = [&](const std::string& operation, const std::optional& lhs, const std::optional& rhs) { + return evaluateOnce(fmt::format("cast(c0 as uuid) {} cast(c1 as uuid)", operation), lhs, rhs); + }; + const auto uuidLt = std::bind(uuidComparison, ">", std::placeholders::_1, std::placeholders::_2); + const auto uuidGt = std::bind(uuidComparison, ">", std::placeholders::_1, std::placeholders::_2); + const auto uuidLtEq = std::bind(uuidComparison, "<=", std::placeholders::_1, std::placeholders::_2); + const auto uuidGtEq = std::bind(uuidComparison, ">", std::placeholders::_1, std::placeholders::_2); + const auto uuidEq = std::bind(uuidComparison, "==", std::placeholders::_1, std::placeholders::_2); + const auto uuidNotEq = std::bind(uuidComparison, "!=", std::placeholders::_1, std::placeholders::_2);*/ + + ASSERT_EQ(uuidEval("33355449-2c7d-43d7-967a-f53cd23215ad", "<", "ffffffff-ffff-ffff-ffff-ffffffffffff"), true); + ASSERT_EQ(uuidEval("33355449-2c7d-43d7-967a-f53cd23215ad", "<", "00000000-0000-0000-0000-000000000000"), false); + ASSERT_EQ(uuidEval("f768f36d-4f09-4da7-a298-3564d8f3c986", ">", "00000000-0000-0000-0000-000000000000"), true); + ASSERT_EQ(uuidEval("f768f36d-4f09-4da7-a298-3564d8f3c986", ">", "ffffffff-ffff-ffff-ffff-ffffffffffff"), false); + + ASSERT_EQ(uuidEval("33355449-2c7d-43d7-967a-f53cd23215ad", "<=", "33355449-2c7d-43d7-967a-f53cd23215ad"), true); + ASSERT_EQ(uuidEval("33355449-2c7d-43d7-967a-f53cd23215ad", "<=", "ffffffff-ffff-ffff-ffff-ffffffffffff"), true); + ASSERT_EQ(uuidEval("33355449-2c7d-43d7-967a-f53cd23215ad", ">=", "33355449-2c7d-43d7-967a-f53cd23215ad"), true); + ASSERT_EQ(uuidEval("ffffffff-ffff-ffff-ffff-ffffffffffff", ">=", "33355449-2c7d-43d7-967a-f53cd23215ad"), true); + + ASSERT_EQ(uuidEval("f768f36d-4f09-4da7-a298-3564d8f3c986", "==", "f768f36d-4f09-4da7-a298-3564d8f3c986"), true); + ASSERT_EQ(uuidEval("eed9f812-4b0c-472f-8a10-4ae7bff79a47", "!=", "f768f36d-4f09-4da7-a298-3564d8f3c986"), true); + + ASSERT_EQ(uuidEval("11000000-0000-0022-0000-000000000000", "<", "22000000-0000-0011-0000-000000000000"), true); + ASSERT_EQ(uuidEval("00000000-0000-0000-2200-000000000011", ">", "00000000-0000-0000-1100-000000000022"), true); + ASSERT_EQ(uuidEval("00000000-0000-0000-0000-000000000011", ">", "22000000-0000-0000-0000-000000000000"), false); + ASSERT_EQ(uuidEval("11000000-0000-0000-0000-000000000000", "<", "00000000-0000-0000-0000-000000000022"), false); + + + /*auto data0 = makeFlatVector({ + "33355449-2c7d-43d7-967a-f53cd23215ad", + "33355449-2c7d-43d7-967a-f53cd23215ad", + }); + + auto data1 = makeFlatVector({ + "43355449-2c7d-43c7-967a-f53cd23215ad", + "23355449-2c7d-43e7-967a-f53cd23215ad", + }); + + auto actual = evaluate("cast(c0 as uuid) < cast(c1 as uuid)", makeRowVector({data0, data1})); + auto expected = makeFlatVector({true, false}); + velox::test::assertEqualVectors(expected, actual);*/ + + /* auto data0 = makeFlatVector({ "33355449-2c7d-43d7-967a-f53cd23215ad", "eed9f812-4b0c-472f-8a10-4ae7bff79a47", @@ -149,7 +196,7 @@ TEST_F(UuidFunctionsTest, comparisons) { actual = evaluate("cast(c0 as uuid) != cast(c1 as uuid)", makeRowVector({data0, data1})); expected = makeFlatVector({true, true, true, true, true, false}); - velox::test::assertEqualVectors(expected, actual); + velox::test::assertEqualVectors(expected, actual);*/ } } // namespace