Skip to content

Commit

Permalink
Add tests for array_union and array_remove with TimestampWithTimezone (
Browse files Browse the repository at this point in the history
…facebookincubator#11222)

Summary:

With facebookincubator#11136 array_union and
array_remove just work with TimestampWithTimezone.

Adding unit tests to verify this and ensure it doesn't break in the future.

Differential Revision: D64196032
  • Loading branch information
Kevin Wilfong authored and facebook-github-bot committed Oct 10, 2024
1 parent a6899b7 commit e1b8a41
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 0 deletions.
51 changes: 51 additions & 0 deletions velox/functions/prestosql/tests/ArrayRemoveTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
#include "velox/common/base/tests/GTestUtils.h"
#include "velox/functions/prestosql/tests/utils/FunctionBaseTest.h"
#include "velox/functions/prestosql/types/TimestampWithTimeZoneType.h"

using namespace facebook::velox;
using namespace facebook::velox::test;
Expand Down Expand Up @@ -207,4 +208,54 @@ TEST_F(ArrayRemoveTest, arrayWithNull) {
testExpression(
"array_remove(c0, c1)", {arrayVector, elementVector}, expected);
}

TEST_F(ArrayRemoveTest, timestampWithTimeZone) {
const auto arrayVector = makeArrayVector(
{0, 6, 13, 16},
makeNullableFlatVector<int64_t>(
{pack(1, 1),
std::nullopt,
pack(2, 2),
pack(3, 3),
std::nullopt,
pack(4, 4),
pack(3, 5),
pack(4, 6),
pack(5, 7),
std::nullopt,
pack(3, 8),
pack(4, 9),
pack(5, 10),
pack(7, 11),
pack(8, 12),
pack(9, 13),
pack(10, 14),
pack(20, 15),
pack(30, 16)},
TIMESTAMP_WITH_TIME_ZONE()));
const auto elementVector = makeFlatVector<int64_t>(
{pack(3, 3), pack(3, 3), pack(33, 1), pack(30, 1)},
TIMESTAMP_WITH_TIME_ZONE());
const auto expected = makeArrayVector(
{0, 5, 10, 13},
makeNullableFlatVector<int64_t>(
{pack(1, 1),
std::nullopt,
pack(2, 2),
std::nullopt,
pack(4, 4),
pack(4, 6),
pack(5, 7),
std::nullopt,
pack(4, 9),
pack(5, 10),
pack(7, 11),
pack(8, 12),
pack(9, 13),
pack(10, 14),
pack(20, 15)},
TIMESTAMP_WITH_TIME_ZONE()));
testExpression(
"array_remove(c0, c1)", {arrayVector, elementVector}, expected);
}
} // namespace
77 changes: 77 additions & 0 deletions velox/functions/prestosql/tests/ArrayUnionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
#include "velox/common/base/tests/GTestUtils.h"
#include "velox/functions/prestosql/tests/utils/FunctionBaseTest.h"
#include "velox/functions/prestosql/types/TimestampWithTimeZoneType.h"

using namespace facebook::velox;
using namespace facebook::velox::test;
Expand Down Expand Up @@ -168,4 +169,80 @@ TEST_F(ArrayUnionTest, floatingPointType) {
floatArrayTest<float>();
floatArrayTest<double>();
}

TEST_F(ArrayUnionTest, timestampWithTimeZone) {
const auto array1 = makeArrayVector(
{0, 4, 7, 10},
makeFlatVector<int64_t>(
{pack(1, 1),
pack(2, 2),
pack(3, 3),
pack(4, 4),
pack(3, 5),
pack(4, 6),
pack(5, 7),
pack(7, 8),
pack(8, 9),
pack(9, 10),
pack(10, 11),
pack(20, 12),
pack(30, 13)},
TIMESTAMP_WITH_TIME_ZONE()));
const auto array2 = makeArrayVector(
{0, 3, 6, 6},
makeFlatVector<int64_t>(
{pack(2, 10),
pack(4, 11),
pack(5, 12),
pack(3, 13),
pack(4, 14),
pack(5, 15),
pack(40, 16),
pack(50, 17)},
TIMESTAMP_WITH_TIME_ZONE()));

VectorPtr expected = makeArrayVector(
{0, 5, 8, 11},
makeFlatVector<int64_t>(
{pack(1, 1),
pack(2, 2),
pack(3, 3),
pack(4, 4),
pack(5, 12),
pack(3, 5),
pack(4, 6),
pack(5, 7),
pack(7, 8),
pack(8, 9),
pack(9, 10),
pack(10, 11),
pack(20, 12),
pack(30, 13),
pack(40, 16),
pack(50, 17)},
TIMESTAMP_WITH_TIME_ZONE()));
testExpression("array_union(c0, c1)", {array1, array2}, expected);

expected = makeArrayVector(
{0, 5, 8, 11},
makeFlatVector<int64_t>(
{pack(2, 10),
pack(4, 11),
pack(5, 12),
pack(1, 1),
pack(3, 3),
pack(3, 13),
pack(4, 14),
pack(5, 15),
pack(7, 8),
pack(8, 9),
pack(9, 10),
pack(40, 16),
pack(50, 17),
pack(10, 11),
pack(20, 12),
pack(30, 13)},
TIMESTAMP_WITH_TIME_ZONE()));
testExpression("array_union(c0, c1)", {array2, array1}, expected);
}
} // namespace

0 comments on commit e1b8a41

Please sign in to comment.