Skip to content

Commit

Permalink
Extend tests for transformXxx Presto lambda functions (facebookincuba…
Browse files Browse the repository at this point in the history
…tor#9289)

Summary:
Pull Request resolved: facebookincubator#9289

Extend tests for transform, transform_keys and transform_values lambda functions
to cover scenario described in
facebookincubator#9288

Reviewed By: bikramSingh91

Differential Revision: D55474277

fbshipit-source-id: 95bf9322430f99924ac0ee41e47aafda9e6959cd
  • Loading branch information
mbasmanova authored and facebook-github-bot committed Mar 29, 2024
1 parent cb58cba commit 90fc393
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 20 deletions.
26 changes: 20 additions & 6 deletions velox/functions/prestosql/tests/TransformKeysTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,33 @@ TEST_F(TransformKeysTest, evaluateSubsetOfRows) {
nullEvery(13)),
});

SelectivityVector inputRows(size, false);
inputRows.setValidRange(0, size / 3, true);
inputRows.updateBounds();
// Test using 2 selectivity vectors. One of size 100 with 33 first rows
// selected. Another of size 33 with all rows selected. Both should produce
// the same result.

auto result = evaluate<MapVector>(
"transform_keys(c0, (k, v) -> k + 5)", input, inputRows);
auto expectedResult = makeMapVector<int64_t, int32_t>(
size / 3,
[](auto row) { return row % 5; },
[](auto row) { return row % 7 + 5; },
[](auto row) { return row % 11; },
nullEvery(13));
assertEqualVectors(expectedResult, result, inputRows);

{
SelectivityVector inputRows(size, false);
inputRows.setValidRange(0, size / 3, true);
inputRows.updateBounds();

auto result = evaluate<MapVector>(
"transform_keys(c0, (k, v) -> k + 5)", input, inputRows);
assertEqualVectors(expectedResult, result, inputRows);
}

{
SelectivityVector inputRows(size / 3);
auto result = evaluate<MapVector>(
"transform_keys(c0, (k, v) -> k + 5)", input, inputRows);
assertEqualVectors(expectedResult, result, inputRows);
}
}

TEST_F(TransformKeysTest, duplicateKeys) {
Expand Down
27 changes: 20 additions & 7 deletions velox/functions/prestosql/tests/TransformTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,32 @@ TEST_F(TransformTest, evaluateSubsetOfRows) {
auto input = makeRowVector(
{makeArrayVector<int64_t>(size, modN(5), modN(7), nullEvery(11))});

SelectivityVector inputRows(size, false);
inputRows.setValidRange(0, size / 3, true);
inputRows.updateBounds();

auto result =
evaluate<ArrayVector>("transform(c0, x -> x + 5)", input, inputRows);
// Test using 2 selectivity vectors. One of size 100 with 33 first rows
// selected. Another of size 33 with all rows selected. Both should produce
// the same result.

auto expectedResult = makeArrayVector<int64_t>(
size / 3,
modN(5),
[](vector_size_t row) { return row % 7 + 5; },
nullEvery(11));
assertEqualVectors(expectedResult, result, inputRows);
{
SelectivityVector inputRows(size, false);
inputRows.setValidRange(0, size / 3, true);
inputRows.updateBounds();

auto result =
evaluate<ArrayVector>("transform(c0, x -> x + 5)", input, inputRows);
assertEqualVectors(expectedResult, result, inputRows);
}

{
SelectivityVector inputRows(size / 3);

auto result =
evaluate<ArrayVector>("transform(c0, x -> x + 5)", input, inputRows);
assertEqualVectors(expectedResult, result, inputRows);
}
}

TEST_F(TransformTest, differentResultType) {
Expand Down
28 changes: 21 additions & 7 deletions velox/functions/prestosql/tests/TransformValuesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,33 @@ TEST_F(TransformValuesTest, evaluateSubsetOfRows) {
nullEvery(13)),
});

SelectivityVector inputRows(size, false);
inputRows.setValidRange(0, size / 3, true);
inputRows.updateBounds();

auto result = evaluate<MapVector>(
"transform_values(c0, (k, v) -> v + 5)", input, inputRows);
// Test using 2 selectivity vectors. One of size 100 with 33 first rows
// selected. Another of size 33 with all rows selected. Both should produce
// the same result.
auto expectedResult = makeMapVector<int32_t, int64_t>(
size / 3,
[](auto row) { return row % 5; },
[](auto row) { return row % 7; },
[](auto row) { return row % 11 + 5; },
nullEvery(13));
assertEqualVectors(expectedResult, result, inputRows);

{
SelectivityVector inputRows(size, false);
inputRows.setValidRange(0, size / 3, true);
inputRows.updateBounds();

auto result = evaluate<MapVector>(
"transform_values(c0, (k, v) -> v + 5)", input, inputRows);
assertEqualVectors(expectedResult, result, inputRows);
}

{
SelectivityVector inputRows(size / 3);

auto result = evaluate<MapVector>(
"transform_values(c0, (k, v) -> v + 5)", input, inputRows);
assertEqualVectors(expectedResult, result, inputRows);
}
}

TEST_F(TransformValuesTest, differentResultType) {
Expand Down

0 comments on commit 90fc393

Please sign in to comment.