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

Method ReadFooterAsync

cpp/src/arrow/ipc/reader.cc:1898–1952  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1896 }
1897
1898 Future<> ReadFooterAsync(arrow::internal::Executor* executor) {
1899 constexpr int32_t kMagicSize = static_cast<int>(kArrowMagicBytes.size());
1900
1901 if (footer_offset_ <= kMagicSize * 2 + 4) {
1902 return Status::Invalid("File is too small: ", footer_offset_);
1903 }
1904
1905 constexpr int64_t kTotalMagicSize = kMagicSize + sizeof(int32_t);
1906 auto self = std::dynamic_pointer_cast<RecordBatchFileReaderImpl>(shared_from_this());
1907 auto read_magic = file_->ReadAsync(footer_offset_ - kTotalMagicSize, kTotalMagicSize,
1908 /*allow_short_read=*/false);
1909 if (executor) read_magic = executor->Transfer(std::move(read_magic));
1910 return read_magic
1911 .Then([=](const std::shared_ptr<Buffer>& buffer)
1912 -> Future<std::shared_ptr<Buffer>> {
1913 DCHECK_EQ(buffer->size(), kTotalMagicSize);
1914 const auto magic_start = buffer->data() + sizeof(int32_t);
1915 if (std::string_view(reinterpret_cast<const char*>(magic_start), kMagicSize) !=
1916 kArrowMagicBytes) {
1917 return Status::Invalid("Not an Arrow file");
1918 }
1919
1920 int32_t footer_length = bit_util::FromLittleEndian(
1921 *reinterpret_cast<const int32_t*>(buffer->data()));
1922
1923 if (footer_length <= 0 ||
1924 footer_length > self->footer_offset_ - kMagicSize * 2 - 4) {
1925 return Status::Invalid("File is smaller than indicated metadata size");
1926 }
1927
1928 // Now read the footer
1929 auto read_footer = self->file_->ReadAsync(
1930 self->footer_offset_ - footer_length - kTotalMagicSize, footer_length,
1931 /*allow_short_read=*/false);
1932 if (executor) read_footer = executor->Transfer(std::move(read_footer));
1933 return read_footer;
1934 })
1935 .Then([=](const std::shared_ptr<Buffer>& buffer) -> Status {
1936 self->footer_buffer_ = buffer;
1937 const auto data = self->footer_buffer_->data();
1938 const auto size = self->footer_buffer_->size();
1939 if (!internal::VerifyFlatbuffers<flatbuf::Footer>(data, size)) {
1940 return Status::IOError("Verification of flatbuffer-encoded Footer failed.");
1941 }
1942 self->footer_ = flatbuf::GetFooter(data);
1943
1944 auto fb_metadata = self->footer_->custom_metadata();
1945 if (fb_metadata != nullptr) {
1946 std::shared_ptr<KeyValueMetadata> md;
1947 ARROW_ASSIGN_OR_RAISE(self->metadata_,
1948 internal::GetKeyValueMetadata(fb_metadata));
1949 }
1950 return Status::OK();
1951 });
1952 }
1953
1954 int num_dictionaries() const {
1955 return static_cast<int>(internal::FlatBuffersVectorSize(footer_->dictionaries()));

Callers

nothing calls this directly

Calls 12

IOErrorFunction · 0.85
GetFooterFunction · 0.85
ThenMethod · 0.80
ARROW_ASSIGN_OR_RAISEFunction · 0.70
GetKeyValueMetadataFunction · 0.70
InvalidFunction · 0.50
FromLittleEndianFunction · 0.50
OKFunction · 0.50
sizeMethod · 0.45
ReadAsyncMethod · 0.45
dataMethod · 0.45
custom_metadataMethod · 0.45

Tested by

no test coverage detected