diff --git a/velox/docs/functions/presto/map.rst b/velox/docs/functions/presto/map.rst index f0cade6e121a..ffb9990083a3 100644 --- a/velox/docs/functions/presto/map.rst +++ b/velox/docs/functions/presto/map.rst @@ -112,7 +112,7 @@ Map Functions ``n`` must be a non-negative BIGINT value.:: SELECT map_top_n(map(ARRAY['a', 'b', 'c'], ARRAY[2, 3, 1]), 2) --- {'b' -> 3, 'a' -> 2} - SELECT map_top_n(map(ARRAY['a', 'b', 'c'], ARRAY[NULL, 3, NULL]), 2) --- {'b' -> 3, 'a' -> NULL} + SELECT map_top_n(map(ARRAY['a', 'b', 'c'], ARRAY[NULL, 3, NULL]), 2) --- {'b' -> 3, 'c' -> NULL} .. function:: map_top_n_keys(map(K,V), n) -> array(K) diff --git a/velox/functions/prestosql/tests/MapTopNTest.cpp b/velox/functions/prestosql/tests/MapTopNTest.cpp index dbbe5cd5c0dc..528283c18955 100644 --- a/velox/functions/prestosql/tests/MapTopNTest.cpp +++ b/velox/functions/prestosql/tests/MapTopNTest.cpp @@ -129,6 +129,16 @@ TEST_F(MapTopNTest, equalValues) { auto expectedResults = makeMapVector({0, 3}, expectedKeys, expectedValues); assertEqualVectors(expectedResults, result); + + auto dataWithStrKey = + makeRowVector({makeMapVectorFromJson( + {R"({"a":2, "b":3, "c":1})", R"({"a":null, "b":3, "c":null})"})}); + + auto resultWithStrKey = evaluate("map_top_n(c0, 2)", dataWithStrKey); + + auto expectedWithStrKey = makeMapVectorFromJson( + {R"({"b":3, "a":2})", R"({"b":3, "c":null})"}); + assertEqualVectors(expectedWithStrKey, resultWithStrKey); } TEST_F(MapTopNTest, timestampWithTimeZone) {