Skip to content

Commit

Permalink
Register map_union_sum(map<BOOLEAN, . >) function
Browse files Browse the repository at this point in the history
Summary: - register map_union_sum(map<BOOLEAN, ..>)  function

Reviewed By: singcha

Differential Revision: D69215688
  • Loading branch information
pradeepvaka authored and facebook-github-bot committed Feb 6, 2025
1 parent 589d657 commit a03a112
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ void registerMapUnionSumAggregate(
"real",
"double",
"varchar",
"json"};
"json",
"boolean"};
const std::vector<std::string> valueTypes = {
"tinyint",
"smallint",
Expand Down Expand Up @@ -416,6 +417,8 @@ void registerMapUnionSumAggregate(
case TypeKind::VARCHAR:
return createMapUnionSumAggregate<StringView>(
valueTypeKind, resultType);
case TypeKind::BOOLEAN:
return createMapUnionSumAggregate<bool>(valueTypeKind, resultType);
default:
VELOX_UNREACHABLE();
}
Expand Down
28 changes: 26 additions & 2 deletions velox/functions/prestosql/aggregates/tests/MapUnionSumTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,30 @@ TEST_F(MapUnionSumTest, groupByJsonKey) {
testAggregations({data}, {"c0"}, {"map_union_sum(c1)"}, {expected});
}

TEST_F(MapUnionSumTest, groupByBooleanKeys) {
auto data = makeRowVector({
makeFlatVector<int64_t>({1, 2, 1, 2, 1}),
makeNullableMapVector<bool, int64_t>({
{}, // empty map
std::nullopt, // null map
{{{true, 10}, {false, 20}}},
{{{true, 11}, {false, 30}, {true, 40}}},
{{{false, 28}, {true, 50}, {true, 12}}},
}),

});

auto expected = makeRowVector({
makeFlatVector<int64_t>({1, 2}),
makeMapVector<bool, int64_t>({
{{{true, 72}, {false, 48}}},
{{{true, 51}, {false, 30}}},
}),
});

testAggregations({data}, {"c0"}, {"map_union_sum(c1)"}, {expected});
}

TEST_F(MapUnionSumTest, floatingPointKeys) {
auto data = makeRowVector({
makeFlatVector<int32_t>({1, 2, 1, 2, 1, 1, 2, 2}),
Expand All @@ -442,8 +466,8 @@ TEST_F(MapUnionSumTest, floatingPointKeys) {
}

TEST_F(MapUnionSumTest, nanKeys) {
// Verify that NaNs with different binary representations are considered equal
// and deduplicated when used as keys in the output map.
// Verify that NaNs with different binary representations are considered
// equal and deduplicated when used as keys in the output map.
constexpr double kNan = std::numeric_limits<double>::quiet_NaN();
constexpr double kSNaN = std::numeric_limits<double>::signaling_NaN();

Expand Down

0 comments on commit a03a112

Please sign in to comment.