Skip to content

Commit

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

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

Reviewed By: kagamiori

Differential Revision: D55902535

fbshipit-source-id: 8c57736859d9f726b1cb7aa43cec74d60990c630
  • Loading branch information
zacw7 authored and facebook-github-bot committed Apr 10, 2024
1 parent 54a7fe8 commit 89de5d3
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 89de5d3

Please sign in to comment.