From 8d5e31717f08d61ac3fd2171a02cf1fbb460109f Mon Sep 17 00:00:00 2001 From: Daniel Hunte Date: Fri, 5 Jul 2024 08:31:42 -0700 Subject: [PATCH] Ongoing clean up of DateTimeStampFunctionsTest.cpp (#10392) Summary: Pull Request resolved: https://github.com/facebookincubator/velox/pull/10392 Velox functions now support the logical type TimeStampWithTimeZone. The use of "evaluateWithTimestampWithTimezone" is therefore no longer needed. Reviewed By: pedroerp Differential Revision: D59338871 fbshipit-source-id: 800a4a69405bbcd30b5112acf94311ae37208a5f --- .../prestosql/tests/DateTimeFunctionsTest.cpp | 108 +++++++++--------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/velox/functions/prestosql/tests/DateTimeFunctionsTest.cpp b/velox/functions/prestosql/tests/DateTimeFunctionsTest.cpp index c7eb59d26821..1fb37b4668f6 100644 --- a/velox/functions/prestosql/tests/DateTimeFunctionsTest.cpp +++ b/velox/functions/prestosql/tests/DateTimeFunctionsTest.cpp @@ -475,7 +475,7 @@ TEST_F(DateTimeFunctionsTest, yearDate) { } TEST_F(DateTimeFunctionsTest, yearTimestampWithTimezone) { - auto yearTimestampWithTimezone = + const auto yearTimestampWithTimezone = [&](std::optional timestampWithTimezone) { return evaluateOnce( "year(c0)", @@ -624,32 +624,37 @@ TEST_F(DateTimeFunctionsTest, quarterDate) { } TEST_F(DateTimeFunctionsTest, quarterTimestampWithTimezone) { + const auto quarterTimestampWithTimezone = + [&](std::optional timestampWithTimezone) { + return evaluateOnce( + "quarter(c0)", + TIMESTAMP_WITH_TIME_ZONE(), + TimestampWithTimezone::pack(timestampWithTimezone)); + }; EXPECT_EQ( - 4, - evaluateWithTimestampWithTimezone("quarter(c0)", 0, "-01:00")); + 4, quarterTimestampWithTimezone(TimestampWithTimezone(0, "-01:00"))); EXPECT_EQ( - 1, - evaluateWithTimestampWithTimezone("quarter(c0)", 0, "+00:00")); + 1, quarterTimestampWithTimezone(TimestampWithTimezone(0, "+00:00"))); EXPECT_EQ( 4, - evaluateWithTimestampWithTimezone( - "quarter(c0)", 123456789000, "+14:00")); + quarterTimestampWithTimezone( + TimestampWithTimezone(123456789000, "+14:00"))); EXPECT_EQ( 1, - evaluateWithTimestampWithTimezone( - "quarter(c0)", -123456789000, "+03:00")); + quarterTimestampWithTimezone( + TimestampWithTimezone(-123456789000, "+03:00"))); EXPECT_EQ( 2, - evaluateWithTimestampWithTimezone( - "quarter(c0)", 987654321000, "-07:00")); + quarterTimestampWithTimezone( + TimestampWithTimezone(987654321000, "-07:00"))); EXPECT_EQ( 3, - evaluateWithTimestampWithTimezone( - "quarter(c0)", -987654321000, "-13:00")); + quarterTimestampWithTimezone( + TimestampWithTimezone(-987654321000, "-13:00"))); EXPECT_EQ( std::nullopt, - evaluateWithTimestampWithTimezone( - "quarter(c0)", std::nullopt, std::nullopt)); + quarterTimestampWithTimezone( + TimestampWithTimezone::unpack(std::nullopt))); } TEST_F(DateTimeFunctionsTest, month) { @@ -689,30 +694,34 @@ TEST_F(DateTimeFunctionsTest, monthDate) { } TEST_F(DateTimeFunctionsTest, monthTimestampWithTimezone) { - EXPECT_EQ( - 12, evaluateWithTimestampWithTimezone("month(c0)", 0, "-01:00")); - EXPECT_EQ( - 1, evaluateWithTimestampWithTimezone("month(c0)", 0, "+00:00")); + const auto monthTimestampWithTimezone = + [&](std::optional timestampWithTimezone) { + return evaluateOnce( + "month(c0)", + TIMESTAMP_WITH_TIME_ZONE(), + TimestampWithTimezone::pack(timestampWithTimezone)); + }; + EXPECT_EQ(12, monthTimestampWithTimezone(TimestampWithTimezone(0, "-01:00"))); + EXPECT_EQ(1, monthTimestampWithTimezone(TimestampWithTimezone(0, "+00:00"))); EXPECT_EQ( 11, - evaluateWithTimestampWithTimezone( - "month(c0)", 123456789000, "+14:00")); + monthTimestampWithTimezone( + TimestampWithTimezone(123456789000, "+14:00"))); EXPECT_EQ( 2, - evaluateWithTimestampWithTimezone( - "month(c0)", -123456789000, "+03:00")); + monthTimestampWithTimezone( + TimestampWithTimezone(-123456789000, "+03:00"))); EXPECT_EQ( 4, - evaluateWithTimestampWithTimezone( - "month(c0)", 987654321000, "-07:00")); + monthTimestampWithTimezone( + TimestampWithTimezone(987654321000, "-07:00"))); EXPECT_EQ( 9, - evaluateWithTimestampWithTimezone( - "month(c0)", -987654321000, "-13:00")); + monthTimestampWithTimezone( + TimestampWithTimezone(-987654321000, "-13:00"))); EXPECT_EQ( std::nullopt, - evaluateWithTimestampWithTimezone( - "month(c0)", std::nullopt, std::nullopt)); + monthTimestampWithTimezone(TimestampWithTimezone::unpack(std::nullopt))); } TEST_F(DateTimeFunctionsTest, hour) { @@ -742,42 +751,33 @@ TEST_F(DateTimeFunctionsTest, hour) { } TEST_F(DateTimeFunctionsTest, hourTimestampWithTimezone) { + const auto hourTimestampWithTimezone = + [&](std::optional timestampWithTimezone) { + return evaluateOnce( + "hour(c0)", + TIMESTAMP_WITH_TIME_ZONE(), + TimestampWithTimezone::pack(timestampWithTimezone)); + }; EXPECT_EQ( 20, - evaluateWithTimestampWithTimezone( - "hour(c0)", 998423705000, "+01:00")); + hourTimestampWithTimezone(TimestampWithTimezone(998423705000, "+01:00"))); EXPECT_EQ( - 12, - evaluateWithTimestampWithTimezone( - "hour(c0)", 41028000, "+01:00")); + 12, hourTimestampWithTimezone(TimestampWithTimezone(41028000, "+01:00"))); EXPECT_EQ( - 13, - evaluateWithTimestampWithTimezone( - "hour(c0)", 41028000, "+02:00")); + 13, hourTimestampWithTimezone(TimestampWithTimezone(41028000, "+02:00"))); EXPECT_EQ( - 14, - evaluateWithTimestampWithTimezone( - "hour(c0)", 41028000, "+03:00")); + 14, hourTimestampWithTimezone(TimestampWithTimezone(41028000, "+03:00"))); EXPECT_EQ( - 8, - evaluateWithTimestampWithTimezone( - "hour(c0)", 41028000, "-03:00")); + 8, hourTimestampWithTimezone(TimestampWithTimezone(41028000, "-03:00"))); EXPECT_EQ( - 1, - evaluateWithTimestampWithTimezone( - "hour(c0)", 41028000, "+14:00")); + 1, hourTimestampWithTimezone(TimestampWithTimezone(41028000, "+14:00"))); EXPECT_EQ( - 9, - evaluateWithTimestampWithTimezone( - "hour(c0)", -100000, "-14:00")); + 9, hourTimestampWithTimezone(TimestampWithTimezone(-100000, "-14:00"))); EXPECT_EQ( - 2, - evaluateWithTimestampWithTimezone( - "hour(c0)", -41028000, "+14:00")); + 2, hourTimestampWithTimezone(TimestampWithTimezone(-41028000, "+14:00"))); EXPECT_EQ( std::nullopt, - evaluateWithTimestampWithTimezone( - "hour(c0)", std::nullopt, std::nullopt)); + hourTimestampWithTimezone(TimestampWithTimezone::unpack(std::nullopt))); } TEST_F(DateTimeFunctionsTest, hourDate) {