Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yma11 committed May 16, 2024
1 parent 7e51483 commit 7f2d605
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion velox/docs/functions/spark/map.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Map Functions

.. spark:function:: map_from_entries(array(struct(K,V))) -> map(K,V)
Returns a map created from the given array of entries. Keys are not allowed to be null or to contain nulls.
Returns a map created from the given array of entries. Exceptions will be thrown if key is null or contains null.
If null entry exists in the array, return null for this whole array.::

SELECT map_from_entries(array(struct(1, 'a'), struct(2, 'null'))); -- {1 -> 'a', 2 -> 'null'}
Expand Down
8 changes: 6 additions & 2 deletions velox/functions/lib/MapFromEntries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class MapFromEntriesFunction : public exec::VectorFunction {
});

auto resetSize = [&](vector_size_t row) { mutableSizes[row] = 0; };
auto nulls = allocateNulls(rows.size(), context.pool());
auto nulls = allocateNulls(decodedRowVector->size(), context.pool());
auto* mutableNulls = nulls->asMutable<uint64_t>();

if (decodedRowVector->mayHaveNulls() || keyVector->mayHaveNulls() ||
Expand Down Expand Up @@ -227,9 +227,13 @@ class MapFromEntriesFunction : public exec::VectorFunction {
}

// For Presto, need construct map vector based on input nulls for possible
// outer expression like try(). For Spark, use the updated nulls.
// outer expression like try(). For Spark, use the updated nulls unless it's empty.
if constexpr (throwForNull) {
nulls = inputArray->nulls();
} else {
if (decodedRowVector->size() == 0) {
nulls = inputArray->nulls();
}
}
auto mapVector = std::make_shared<MapVector>(
context.pool(),
Expand Down
3 changes: 0 additions & 3 deletions velox/functions/sparksql/tests/MapFromEntriesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@
* limitations under the License.
*/
#include <cstdint>
#include <optional>
#include "velox/common/base/tests/GTestUtils.h"
#include "velox/functions/lib/CheckDuplicateKeys.h"
#include "velox/functions/prestosql/ArrayConstructor.h"
#include "velox/functions/sparksql/tests/SparkFunctionBaseTest.h"
#include "velox/vector/tests/TestingDictionaryArrayElementsFunction.h"

using namespace facebook::velox::test;

Expand Down

0 comments on commit 7f2d605

Please sign in to comment.