diff --git a/velox/functions/prestosql/MapTopN.h b/velox/functions/prestosql/MapTopN.h index 1407dc0680f71..a2b9ba4229339 100644 --- a/velox/functions/prestosql/MapTopN.h +++ b/velox/functions/prestosql/MapTopN.h @@ -60,11 +60,6 @@ struct MapTopNFunction { return; } - if (n >= inputMap.size()) { - out.copy_from(inputMap); - return; - } - using It = typename arg_type, Orderable>>::Iterator; Compare comparator; diff --git a/velox/functions/prestosql/tests/MapTopNTest.cpp b/velox/functions/prestosql/tests/MapTopNTest.cpp index ca3e758e7884c..75e4f3984cc8f 100644 --- a/velox/functions/prestosql/tests/MapTopNTest.cpp +++ b/velox/functions/prestosql/tests/MapTopNTest.cpp @@ -66,6 +66,22 @@ TEST_F(MapTopNTest, basic) { "n must be greater than or equal to 0"); } +TEST_F(MapTopNTest, nestedNullFailure) { + auto data = makeMapVector( + /*offsets=*/{0}, + /*keyVector=*/makeFlatVector({1, 2, 3}), + /*valueVector=*/ + makeNullableArrayVector({{std::nullopt}, {2}, {5}})); + + // Nested nulls present inhibit the orderbility of values. Expect an error. + VELOX_ASSERT_THROW( + evaluate("map_top_n(c0, 1)", makeRowVector({data})), + "Ordering nulls is not supported"); + VELOX_ASSERT_THROW( + evaluate("map_top_n(c0, 10)", makeRowVector({data})), + "Ordering nulls is not supported"); +} + // Test to ensure we use keys to break ties if values are // equal. TEST_F(MapTopNTest, equalValues) {