MCPcopy Create free account
hub / github.com/apache/arrow / MakeListArray

Function MakeListArray

cpp/src/parquet/arrow/test_util.h:382–417  ·  view source on GitHub ↗

Wrap an Array into a ListArray by splitting it up into size lists. This helper function only supports (size/2) nulls.

Source from the content-addressed store, hash-verified

380///
381/// This helper function only supports (size/2) nulls.
382Status MakeListArray(const std::shared_ptr<Array>& values, int64_t size,
383 int64_t null_count, const std::string& item_name,
384 bool nullable_values, std::shared_ptr<::arrow::ListArray>* out) {
385 // We always include an empty list
386 int64_t non_null_entries = size - null_count - 1;
387 int64_t length_per_entry = values->length() / non_null_entries;
388
389 auto offsets = AllocateBuffer();
390 RETURN_NOT_OK(offsets->Resize((size + 1) * sizeof(int32_t)));
391 int32_t* offsets_ptr = reinterpret_cast<int32_t*>(offsets->mutable_data());
392
393 auto null_bitmap = AllocateBuffer();
394 int64_t bitmap_size = ::arrow::bit_util::BytesForBits(size);
395 RETURN_NOT_OK(null_bitmap->Resize(bitmap_size));
396 uint8_t* null_bitmap_ptr = null_bitmap->mutable_data();
397 memset(null_bitmap_ptr, 0, bitmap_size);
398
399 int32_t current_offset = 0;
400 for (int64_t i = 0; i < size; i++) {
401 offsets_ptr[i] = current_offset;
402 if (!(((i % 2) == 0) && ((i / 2) < null_count))) {
403 // Non-null list (list with index 1 is always empty).
404 ::arrow::bit_util::SetBit(null_bitmap_ptr, i);
405 if (i != 1) {
406 current_offset += static_cast<int32_t>(length_per_entry);
407 }
408 }
409 }
410 offsets_ptr[size] = static_cast<int32_t>(values->length());
411
412 auto value_field = ::arrow::field(item_name, values->type(), nullable_values);
413 *out = std::make_shared<::arrow::ListArray>(::arrow::list(value_field), size, offsets,
414 values, null_bitmap, null_count);
415
416 return Status::OK();
417}
418
419// Make an array containing only empty lists, with a null values array
420Status MakeEmptyListsArray(int64_t size, std::shared_ptr<Array>* out_array) {

Callers 2

PrepareListTableMethod · 0.70

Calls 10

BytesForBitsFunction · 0.85
SetBitFunction · 0.85
listFunction · 0.85
fieldFunction · 0.70
AllocateBufferFunction · 0.50
OKFunction · 0.50
lengthMethod · 0.45
ResizeMethod · 0.45
mutable_dataMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected