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

Function CleanListOffsets

cpp/src/arrow/array/array_nested.cc:65–101  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63/// \pre offsets.null_count() > 0
64template <typename TYPE>
65Result<BufferVector> CleanListOffsets(const std::shared_ptr<Buffer>& validity_buffer,
66 const Array& offsets, MemoryPool* pool) {
67 using offset_type = typename TYPE::offset_type;
68 using OffsetArrowType = typename CTypeTraits<offset_type>::ArrowType;
69 using OffsetArrayType = typename TypeTraits<OffsetArrowType>::ArrayType;
70
71 DCHECK_GT(offsets.null_count(), 0);
72 const int64_t num_offsets = offsets.length();
73
74 if (!offsets.IsValid(num_offsets - 1)) {
75 return Status::Invalid("Last list offset should be non-null");
76 }
77
78 ARROW_ASSIGN_OR_RAISE(auto clean_offsets,
79 AllocateBuffer(num_offsets * sizeof(offset_type), pool));
80
81 // Copy valid bits, ignoring the final offset (since for a length N list array,
82 // we have N + 1 offsets)
83 ARROW_ASSIGN_OR_RAISE(
84 auto clean_validity_buffer,
85 CopyBitmap(pool, offsets.null_bitmap()->data(), offsets.offset(), num_offsets - 1));
86
87 const offset_type* raw_offsets =
88 checked_cast<const OffsetArrayType&>(offsets).raw_values();
89 auto clean_raw_offsets = reinterpret_cast<offset_type*>(clean_offsets->mutable_data());
90
91 // Must work backwards so we can tell how many values were in the last non-null value
92 offset_type current_offset = raw_offsets[num_offsets - 1];
93 for (int64_t i = num_offsets - 1; i >= 0; --i) {
94 if (offsets.IsValid(i)) {
95 current_offset = raw_offsets[i];
96 }
97 clean_raw_offsets[i] = current_offset;
98 }
99
100 return BufferVector({std::move(clean_validity_buffer), std::move(clean_offsets)});
101}
102
103template <typename TYPE>
104Result<std::shared_ptr<typename TypeTraits<TYPE>::ArrayType>> ListArrayFromArrays(

Callers

nothing calls this directly

Calls 6

InvalidFunction · 0.50
null_countMethod · 0.45
lengthMethod · 0.45
IsValidMethod · 0.45
raw_valuesMethod · 0.45
mutable_dataMethod · 0.45

Tested by

no test coverage detected