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

Function ViewOffsetsFromLengthsArray

cpp/src/arrow/testing/random.cc:777–816  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

775/// \param[out] out_max_view_end The maximum value of the end of a list-view
776template <typename OffsetArrayType, typename offset_type>
777std::shared_ptr<Array> ViewOffsetsFromLengthsArray(
778 SeedType seed, OffsetArrayType& mutable_sizes_array, bool force_empty_nulls,
779 bool zero_undefined_offsets, int64_t* out_max_view_end, int64_t alignment,
780 MemoryPool* memory_pool) {
781 using TypeClass = typename OffsetArrayType::TypeClass;
782
783 auto* sizes = mutable_sizes_array.data()->template GetMutableValues<offset_type>(1);
784
785 BufferVector buffers{2};
786 buffers[0] = NULLPTR; // sizes can have nulls, offsets don't have to
787 buffers[1] = *AllocateBuffer(sizeof(offset_type) * mutable_sizes_array.length(),
788 alignment, memory_pool);
789 auto offsets = buffers[1]->mutable_data_as<offset_type>();
790
791 offset_type offset = 0;
792 offset_type max_view_end = 0;
793 for (int64_t i = 0; i < mutable_sizes_array.length(); ++i) {
794 if (mutable_sizes_array.IsNull(i)) {
795 if (force_empty_nulls) {
796 sizes[i] = 0;
797 }
798 offsets[i] = zero_undefined_offsets ? 0 : offset;
799 } else {
800 if (sizes[i] == 0) {
801 offsets[i] = zero_undefined_offsets ? 0 : offset;
802 } else {
803 offsets[i] = offset;
804 DCHECK_LT(offset, std::numeric_limits<offset_type>::max() - sizes[i]);
805 offset += sizes[i];
806 }
807 }
808 max_view_end = std::max(max_view_end, offsets[i] + sizes[i]);
809 }
810 *out_max_view_end = max_view_end;
811
812 auto array_data =
813 ArrayData::Make(TypeTraits<TypeClass>::type_singleton(),
814 mutable_sizes_array.length(), std::move(buffers), /*null_count=*/0);
815 return std::make_shared<OffsetArrayType>(std::move(array_data));
816}
817
818template <typename ArrayType, typename RAG>
819Result<std::shared_ptr<Array>> ArrayOfListView(RAG& self, const Field& field,

Callers

nothing calls this directly

Calls 6

AllocateBufferFunction · 0.50
MakeFunction · 0.50
type_singletonFunction · 0.50
dataMethod · 0.45
lengthMethod · 0.45
IsNullMethod · 0.45

Tested by

no test coverage detected