Skip to content

Commit

Permalink
Add support for UNKNOWN key to map_agg Presto aggregate function (fac…
Browse files Browse the repository at this point in the history
…ebookincubator#8452)

Summary:
Pull Request resolved: facebookincubator#8452

Presto aggregation function map_agg(key, value) allows keys of UNKNOWN type.

Reviewed By: pedroerp

Differential Revision: D52906716

fbshipit-source-id: 2379286a370f650267b25293c739e02495caf273
  • Loading branch information
mbasmanova authored and facebook-github-bot committed Jan 19, 2024
1 parent 2645613 commit f0ac5fa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion velox/functions/prestosql/aggregates/MapAggAggregate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class MapAggAggregate : public MapAggregateBase<K> {
void registerMapAggAggregate(const std::string& prefix) {
std::vector<std::shared_ptr<exec::AggregateFunctionSignature>> signatures{
exec::AggregateFunctionSignatureBuilder()
.knownTypeVariable("K")
.typeVariable("K")
.typeVariable("V")
.returnType("map(K,V)")
.intermediateType("map(K,V)")
Expand Down
24 changes: 24 additions & 0 deletions velox/functions/prestosql/aggregates/tests/MapAggTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,30 @@ TEST_F(MapAggTest, selectiveMaskWithDuplicates) {
assertQuery(plan, {expectedResult});
}

TEST_F(MapAggTest, unknownKey) {
auto data = makeRowVector({
makeFlatVector<int8_t>({1, 2, 1, 2, 1, 2, 1, 2, 1, 2}),
makeAllNullFlatVector<UnknownValue>(10),
makeConstant<int32_t>(123, 10),
});

testAggregations(
{data},
{"c0"},
{"map_agg(c1, c2)"},
"VALUES (1, NULL), (2, NULL)",
{},
false /*testWithTableScan*/);

testAggregations(
{data},
{},
{"map_agg(c1, c2)"},
"VALUES (NULL)",
{},
false /*testWithTableScan*/);
}

TEST_F(MapAggTest, stringLifeCycle) {
vector_size_t num = 10;
std::vector<std::string> s(num);
Expand Down

0 comments on commit f0ac5fa

Please sign in to comment.