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

Function ReadFieldsSubset

cpp/src/arrow/ipc/message.cc:287–319  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

285namespace {
286
287Status ReadFieldsSubset(int64_t offset, io::RandomAccessFile* file,
288 const FieldsLoaderFunction& fields_loader,
289 const std::shared_ptr<Buffer>& metadata, int64_t required_size,
290 std::shared_ptr<Buffer>& body) {
291 DCHECK_GE(static_cast<size_t>(metadata->size()), sizeof(int32_t));
292 const auto continuation = util::SafeLoadAs<int32_t>(metadata->data());
293 // Either 8 bytes (32-bit continuation indicator + 32-bit little-endian length prefix)
294 // or 4 bytes for legacy IPC without continuation indicator
295 const auto continuation_size = (continuation == internal::kIpcContinuationToken)
296 ? 2 * sizeof(int32_t)
297 : sizeof(int32_t);
298
299 const flatbuf::Message* message = nullptr;
300 RETURN_NOT_OK(internal::VerifyMessage(metadata->data() + continuation_size,
301 metadata->size() - continuation_size, &message));
302 auto batch = message->header_as_RecordBatch();
303 if (batch == nullptr) {
304 return Status::IOError(
305 "Header-type of flatbuffer-encoded Message is not RecordBatch.");
306 }
307 internal::IoRecordedRandomAccessFile io_recorded_random_access_file(required_size);
308 RETURN_NOT_OK(fields_loader(batch, &io_recorded_random_access_file));
309 const auto& read_ranges = io_recorded_random_access_file.GetReadRanges();
310 for (const auto& range : read_ranges) {
311 auto read_result = file->ReadAt(offset + metadata->size() + range.offset,
312 range.length, body->mutable_data() + range.offset);
313 if (!read_result.ok()) {
314 return Status::IOError("Failed to read message body, error ",
315 read_result.status().ToString());
316 }
317 }
318 return Status::OK();
319}
320
321struct ReadMessageState {
322 std::unique_ptr<Message> result;

Callers 1

ReadMessageContinuedFunction · 0.85

Calls 11

VerifyMessageFunction · 0.85
IOErrorFunction · 0.85
OKFunction · 0.50
sizeMethod · 0.45
dataMethod · 0.45
GetReadRangesMethod · 0.45
ReadAtMethod · 0.45
mutable_dataMethod · 0.45
okMethod · 0.45
ToStringMethod · 0.45
statusMethod · 0.45

Tested by

no test coverage detected