AlenkaF commented on code in PR #41956:
URL: https://github.com/apache/arrow/pull/41956#discussion_r1629360321
##########
cpp/src/arrow/array/array_nested.cc:
##########
@@ -847,14 +847,13 @@ Result<std::shared_ptr<Array>>
MapArray::FromArraysInternal(
const auto& typed_offsets = checked_cast<const OffsetArrayType&>(*offsets);
BufferVector buffers;
- int64_t null_count;
- if (null_bitmap != nullptr) {
- buffers = BufferVector({std::move(null_bitmap), typed_offsets.values()});
- null_count = null_bitmap->size();
- } else {
- buffers = BufferVector({null_bitmap, typed_offsets.values()});
- null_count = 0;
+ buffers.resize(2);
+ int64_t null_count = 0;
+ if (null_bitmap) {
+ buffers[0] = std::move(null_bitmap);
Review Comment:
I might be missing something but removing `const` in `null_bitmap ` from
`FromArraysInternal` and both `MapArray::FromArrays` I get the following error:
```
/Users/alenkafrim/repos/arrow/cpp/src/arrow/array/array_nested.h:540:32:
error: non-const lvalue reference to type 'std::shared_ptr<Buffer>' cannot bind
to a temporary of type 'std::nullptr_t'
std::shared_ptr<Buffer>& null_bitmap = NULLPTR);
^ ~~~~~~~
/Users/alenkafrim/repos/arrow/cpp/src/arrow/array/array_nested.h:540:32:
note: passing argument to parameter 'null_bitmap' here
/Users/alenkafrim/repos/arrow/cpp/src/arrow/array/array_nested.h:546:32:
error: non-const lvalue reference to type 'std::shared_ptr<Buffer>' cannot bind
to a temporary of type 'std::nullptr_t'
std::shared_ptr<Buffer>& null_bitmap = NULLPTR);
^ ~~~~~~~
/Users/alenkafrim/repos/arrow/cpp/src/arrow/array/array_nested.h:546:32:
note: passing argument to parameter 'null_bitmap' here
/Users/alenkafrim/repos/arrow/cpp/src/arrow/array/array_nested.h:566:50:
error: non-const lvalue reference to type 'std::shared_ptr<Buffer>' cannot bind
to a temporary of type 'std::nullptr_t'
MemoryPool* pool, std::shared_ptr<Buffer>& null_bitmap = NULLPTR);
```
the diff is:
```
diff --git a/cpp/src/arrow/array/array_nested.cc
b/cpp/src/arrow/array/array_nested.cc
index fb2efe9ae..49f67a180 100644
--- a/cpp/src/arrow/array/array_nested.cc
+++ b/cpp/src/arrow/array/array_nested.cc
@@ -807,7 +807,7 @@ MapArray::MapArray(const std::shared_ptr<DataType>&
type, int64_t length,
Result<std::shared_ptr<Array>> MapArray::FromArraysInternal(
std::shared_ptr<DataType> type, const std::shared_ptr<Array>& offsets,
const std::shared_ptr<Array>& keys, const std::shared_ptr<Array>& items,
- MemoryPool* pool, const std::shared_ptr<Buffer>& null_bitmap) {
+ MemoryPool* pool, std::shared_ptr<Buffer>& null_bitmap) {
using offset_type = typename MapType::offset_type;
using OffsetArrowType = typename CTypeTraits<offset_type>::ArrowType;
@@ -861,7 +861,7 @@ Result<std::shared_ptr<Array>>
MapArray::FromArraysInternal(
Result<std::shared_ptr<Array>> MapArray::FromArrays(
const std::shared_ptr<Array>& offsets, const std::shared_ptr<Array>&
keys,
const std::shared_ptr<Array>& items, MemoryPool* pool,
- const std::shared_ptr<Buffer>& null_bitmap) {
+ std::shared_ptr<Buffer>& null_bitmap) {
return FromArraysInternal(std::make_shared<MapType>(keys->type(),
items->type()),
offsets, keys, items, pool, null_bitmap);
}
@@ -869,7 +869,7 @@ Result<std::shared_ptr<Array>> MapArray::FromArrays(
Result<std::shared_ptr<Array>> MapArray::FromArrays(
std::shared_ptr<DataType> type, const std::shared_ptr<Array>& offsets,
const std::shared_ptr<Array>& keys, const std::shared_ptr<Array>& items,
- MemoryPool* pool, const std::shared_ptr<Buffer>& null_bitmap) {
+ MemoryPool* pool, std::shared_ptr<Buffer>& null_bitmap) {
if (type->id() != Type::MAP) {
return Status::TypeError("Expected map type, got ", type->ToString());
}
diff --git a/cpp/src/arrow/array/array_nested.h
b/cpp/src/arrow/array/array_nested.h
index f96b6bd3b..173147f55 100644
--- a/cpp/src/arrow/array/array_nested.h
+++ b/cpp/src/arrow/array/array_nested.h
@@ -537,13 +537,13 @@ class ARROW_EXPORT MapArray : public ListArray {
static Result<std::shared_ptr<Array>> FromArrays(
const std::shared_ptr<Array>& offsets, const std::shared_ptr<Array>&
keys,
const std::shared_ptr<Array>& items, MemoryPool* pool =
default_memory_pool(),
- const std::shared_ptr<Buffer>& null_bitmap = NULLPTR);
+ std::shared_ptr<Buffer>& null_bitmap = NULLPTR);
static Result<std::shared_ptr<Array>> FromArrays(
std::shared_ptr<DataType> type, const std::shared_ptr<Array>& offsets,
const std::shared_ptr<Array>& keys, const std::shared_ptr<Array>&
items,
MemoryPool* pool = default_memory_pool(),
- const std::shared_ptr<Buffer>& null_bitmap = NULLPTR);
+ std::shared_ptr<Buffer>& null_bitmap = NULLPTR);
const MapType* map_type() const { return map_type_; }
@@ -563,7 +563,7 @@ class ARROW_EXPORT MapArray : public ListArray {
static Result<std::shared_ptr<Array>> FromArraysInternal(
std::shared_ptr<DataType> type, const std::shared_ptr<Array>& offsets,
const std::shared_ptr<Array>& keys, const std::shared_ptr<Array>&
items,
- MemoryPool* pool, const std::shared_ptr<Buffer>& null_bitmap =
NULLPTR);
+ MemoryPool* pool, std::shared_ptr<Buffer>& null_bitmap = NULLPTR);
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]