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

Method GetZeroBasedValueOffsets

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

Source from the content-addressed store, hash-verified

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