Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update the Description of map_top_n #12216

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion velox/docs/functions/presto/map.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 10 additions & 0 deletions velox/functions/prestosql/tests/MapTopNTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ TEST_F(MapTopNTest, equalValues) {
auto expectedResults = makeMapVector({0, 3}, expectedKeys, expectedValues);

assertEqualVectors(expectedResults, result);

auto dataWithStrKey =
makeRowVector({makeMapVectorFromJson<std::string, int64_t>(
{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<std::string, int64_t>(
{R"({"b":3, "a":2})", R"({"b":3, "c":null})"});
assertEqualVectors(expectedWithStrKey, resultWithStrKey);
}

TEST_F(MapTopNTest, timestampWithTimeZone) {
Expand Down
Loading