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

Function ListArrayFromArrays

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

Source from the content-addressed store, hash-verified

102
103template <typename TYPE>
104Result<std::shared_ptr<typename TypeTraits<TYPE>::ArrayType>> ListArrayFromArrays(
105 std::shared_ptr<DataType> type, const Array& offsets, const Array& values,
106 MemoryPool* pool, std::shared_ptr<Buffer> null_bitmap = NULLPTR,
107 int64_t null_count = kUnknownNullCount) {
108 using offset_type = typename TYPE::offset_type;
109 using ArrayType = typename TypeTraits<TYPE>::ArrayType;
110 using OffsetArrowType = typename CTypeTraits<offset_type>::ArrowType;
111
112 if (offsets.length() == 0) {
113 return Status::Invalid("List offsets must have non-zero length");
114 }
115
116 if (offsets.type_id() != OffsetArrowType::type_id) {
117 return Status::TypeError("List offsets must be ", OffsetArrowType::type_name());
118 }
119
120 if (null_bitmap != nullptr && offsets.data()->GetNullCount() != 0) {
121 return Status::Invalid(
122 "Ambiguous to specify both validity map and offsets with nulls");
123 }
124
125 if (null_bitmap != nullptr && offsets.offset() != 0) {
126 return Status::NotImplemented("Null bitmap with offsets slice not supported.");
127 }
128
129 // Clean the offsets if they contain nulls.
130 if (offsets.null_count() > 0) {
131 ARROW_ASSIGN_OR_RAISE(auto buffers,
132 CleanListOffsets<TYPE>(null_bitmap, offsets, pool));
133 auto data = ArrayData::Make(type, offsets.length() - 1, std::move(buffers),
134 {values.data()}, offsets.null_count(), /*offset=*/0);
135 return std::make_shared<ArrayType>(std::move(data));
136 }
137
138 using OffsetArrayType = typename TypeTraits<OffsetArrowType>::ArrayType;
139 const auto& typed_offsets = checked_cast<const OffsetArrayType&>(offsets);
140 auto buffers = BufferVector({std::move(null_bitmap), typed_offsets.values()});
141 auto data = ArrayData::Make(type, offsets.length() - 1, std::move(buffers),
142 {values.data()}, null_count, offsets.offset());
143 return std::make_shared<ArrayType>(std::move(data));
144}
145
146template <typename TYPE>
147Result<std::shared_ptr<typename TypeTraits<TYPE>::ArrayType>> ListViewArrayFromArrays(

Callers

nothing calls this directly

Calls 12

GetNullCountMethod · 0.80
MakeFunction · 0.70
InvalidFunction · 0.50
TypeErrorFunction · 0.50
type_nameFunction · 0.50
NotImplementedFunction · 0.50
lengthMethod · 0.45
type_idMethod · 0.45
dataMethod · 0.45
offsetMethod · 0.45
null_countMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected