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

Method GetZeroBasedValueOffsets

cpp/src/arrow/ipc/writer.cc:324–369  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

322
323 template <typename ArrayType>
324 Status GetZeroBasedValueOffsets(const ArrayType& array,
325 std::shared_ptr<Buffer>* value_offsets) {
326 // Share slicing logic between ListArray, BinaryArray and LargeBinaryArray
327 using offset_type = typename ArrayType::offset_type;
328
329 if (array.length() == 0) {
330 *value_offsets = array.value_offsets();
331 return Status::OK();
332 }
333
334 const int64_t required_bytes = sizeof(offset_type) * (array.length() + 1);
335
336 offset_type first_offset = 0;
337 RETURN_NOT_OK(MemoryManager::CopyBufferSliceToCPU(
338 array.data()->buffers[1], array.offset() * sizeof(offset_type),
339 sizeof(offset_type), reinterpret_cast<uint8_t*>(&first_offset)));
340
341 if (first_offset > 0) {
342 // If the offset of the first value is non-zero, then we must create a new
343 // offsets buffer with shifted offsets.
344 if (!array.data()->buffers[1]->is_cpu()) {
345 return Status::NotImplemented("Rebasing non-CPU offsets");
346 }
347 ARROW_ASSIGN_OR_RAISE(auto shifted_offsets,
348 AllocateBuffer(required_bytes, options_.memory_pool));
349
350 const offset_type* source_offsets = array.raw_value_offsets();
351 auto dest_offsets = shifted_offsets->mutable_span_as<offset_type>();
352 const offset_type start_offset = source_offsets[0];
353
354 for (int i = 0; i <= array.length(); ++i) {
355 dest_offsets[i] = source_offsets[i] - start_offset;
356 }
357 *value_offsets = std::move(shifted_offsets);
358 } else {
359 // ARROW-6046: if we have a truncated slice with unused leading or
360 // trailing data, then we slice it.
361 if (array.offset() > 0 || array.value_offsets()->size() > required_bytes) {
362 *value_offsets = SliceBuffer(
363 array.value_offsets(), array.offset() * sizeof(offset_type), required_bytes);
364 } else {
365 *value_offsets = array.value_offsets();
366 }
367 }
368 return Status::OK();
369 }
370
371 template <typename ArrayType, typename offset_type = typename ArrayType::offset_type>
372 Status GetZeroBasedListViewOffsets(const ArrayType& array,

Callers

nothing calls this directly

Calls 9

SliceBufferFunction · 0.85
value_offsetsMethod · 0.80
OKFunction · 0.50
NotImplementedFunction · 0.50
lengthMethod · 0.45
dataMethod · 0.45
offsetMethod · 0.45
raw_value_offsetsMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected