Skip to content

Commit

Permalink
Support UNKNOWN type in Map function (#9410)
Browse files Browse the repository at this point in the history
Summary:

Currently the key type of `MAP` is specified as `knownTypeVariable` which refuses to bind `UNKNOWN` type, while in Presto `MAP(UNKNOWN, UNKNOWN)` is valid.

Differential Revision: D55902535
  • Loading branch information
zacw7 authored and facebook-github-bot committed Apr 9, 2024
1 parent 3558eb7 commit 7fd7828
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion velox/functions/prestosql/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class MapFunction : public exec::VectorFunction {
static std::vector<std::shared_ptr<exec::FunctionSignature>> signatures() {
// array(K), array(V) -> map(K,V)
return {exec::FunctionSignatureBuilder()
.knownTypeVariable("K")
.typeVariable("K")
.typeVariable("V")
.returnType("map(K,V)")
.argumentType("array(K)")
Expand Down
17 changes: 17 additions & 0 deletions velox/functions/prestosql/tests/MapTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,4 +420,21 @@ TEST_F(MapTest, nestedNullInKeys) {
"map key cannot be indeterminate");
}

TEST_F(MapTest, unknownType) {
// MAP(ARRAY[], ARRAY[])
auto emptyArrayVector = makeArrayVector<UnknownValue>({{}});
auto expectedMap = makeMapVector<UnknownValue, UnknownValue>({{}});
auto result = evaluate(
"map(c0, c1)", makeRowVector({emptyArrayVector, emptyArrayVector}));
assertEqualVectors(expectedMap, result);

// MAP(ARRAY[null], ARRAY[null])
auto elementVector = makeNullableFlatVector<UnknownValue>({std::nullopt});
auto nullArrayVector = makeArrayVector({0}, elementVector);
VELOX_ASSERT_THROW(
evaluate(
"map(c0, c1)", makeRowVector({nullArrayVector, nullArrayVector})),
"map key cannot be null");
}

} // namespace

0 comments on commit 7fd7828

Please sign in to comment.