iceberg/spec/manifest_list/reader.rs
1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18use super::ManifestList;
19use crate::error::Result;
20use crate::io::FileIO;
21use crate::spec::{SnapshotRef, TableMetadataRef};
22
23/// A manifest list reader that encapsulates the logic for loading and parsing a [`ManifestList`]
24/// from a snapshot.
25pub struct ManifestListReader {
26 snapshot: SnapshotRef,
27 file_io: FileIO,
28 table_metadata: TableMetadataRef,
29}
30
31impl ManifestListReader {
32 pub(crate) fn new(
33 snapshot: SnapshotRef,
34 file_io: FileIO,
35 table_metadata: TableMetadataRef,
36 ) -> Self {
37 Self {
38 snapshot,
39 file_io,
40 table_metadata,
41 }
42 }
43
44 /// Loads and returns the [`ManifestList`] for this snapshot.
45 pub async fn load(&self) -> Result<ManifestList> {
46 let manifest_list_content = self
47 .file_io
48 .new_input(self.snapshot.manifest_list())?
49 .read()
50 .await?;
51 ManifestList::parse_with_version(
52 &manifest_list_content,
53 self.table_metadata.format_version(),
54 )
55 }
56}