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

Method VisitArray

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

Source from the content-addressed store, hash-verified

144 virtual ~RecordBatchSerializer() = default;
145
146 Status VisitArray(const Array& arr) {
147 static std::shared_ptr<Buffer> kNullBuffer = std::make_shared<Buffer>(nullptr, 0);
148
149 if (max_recursion_depth_ <= 0) {
150 return Status::Invalid("Max recursion depth reached");
151 }
152
153 // An extension array is serialized as its storage array: the extension type
154 // itself is carried in the schema, not in the record batch body. The storage
155 // array shares the extension array's ArrayData, so length, offset and null
156 // count are unchanged; only the type id differs, and it is the storage type id
157 // that decides the buffer layout below.
158 const Array& physical_arr = arr.type_id() == Type::EXTENSION
159 ? *checked_cast<const ExtensionArray&>(arr).storage()
160 : arr;
161
162 if (!options_.allow_64bit &&
163 physical_arr.length() > std::numeric_limits<int32_t>::max()) {
164 return Status::CapacityError("Cannot write arrays larger than 2^31 - 1 in length");
165 }
166
167 if (physical_arr.offset() != 0 &&
168 physical_arr.device_type() != DeviceAllocationType::kCPU) {
169 // https://github.com/apache/arrow/issues/43029
170 return Status::NotImplemented("Cannot compute null count for non-cpu sliced array");
171 }
172
173 // push back all common elements
174 field_nodes_.push_back({physical_arr.length(), physical_arr.null_count(), 0});
175
176 // In V4, null types have no validity bitmap
177 // In V5 and later, null and union types have no validity bitmap
178 if (internal::HasValidityBitmap(physical_arr.type_id(), options_.metadata_version)) {
179 if (physical_arr.null_count() > 0) {
180 std::shared_ptr<Buffer> bitmap;
181 RETURN_NOT_OK(GetTruncatedBitmap(physical_arr.offset(), physical_arr.length(),
182 physical_arr.null_bitmap(), options_.memory_pool,
183 &bitmap));
184 out_->body_buffers.emplace_back(std::move(bitmap));
185 } else {
186 // Push a dummy zero-length buffer, not to be copied
187 out_->body_buffers.emplace_back(kNullBuffer);
188 }
189 }
190 return VisitType(physical_arr);
191 }
192
193 // Override this for writing dictionary metadata
194 virtual Status SerializeMetadata(int64_t num_rows) {

Callers

nothing calls this directly

Calls 13

CapacityErrorFunction · 0.85
GetTruncatedBitmapFunction · 0.85
push_backMethod · 0.80
emplace_backMethod · 0.80
HasValidityBitmapFunction · 0.70
InvalidFunction · 0.50
NotImplementedFunction · 0.50
VisitTypeFunction · 0.50
type_idMethod · 0.45
lengthMethod · 0.45
offsetMethod · 0.45
device_typeMethod · 0.45

Tested by

no test coverage detected