iceberg-cpp
Loading...
Searching...
No Matches
manifest_reader_internal.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
24
25#include <memory>
26#include <optional>
27#include <string>
28#include <vector>
29
33#include "iceberg/file_reader.h"
36#include "iceberg/util/partition_value_util.h"
37
38namespace iceberg {
39
46 public:
58 ManifestReaderImpl(std::string manifest_path, std::optional<int64_t> manifest_length,
59 std::shared_ptr<FileIO> file_io, std::shared_ptr<Schema> schema,
60 std::shared_ptr<PartitionSpec> spec,
61 std::unique_ptr<InheritableMetadata> inheritable_metadata,
62 std::optional<int64_t> first_row_id, bool is_committed);
63
64 Result<std::vector<ManifestEntry>> Entries() override;
65
66 Result<std::vector<ManifestEntry>> LiveEntries() override;
67
68 ManifestReader& Select(const std::vector<std::string>& columns) override;
69
70 ManifestReader& FilterPartitions(std::shared_ptr<Expression> expr) override;
71
72 ManifestReader& FilterPartitions(std::shared_ptr<PartitionSet> partition_set) override;
73
74 ManifestReader& FilterRows(std::shared_ptr<Expression> expr) override;
75
76 ManifestReader& CaseSensitive(bool case_sensitive) override;
77
78 ManifestReader& TryDropStats() override;
79
80 private:
82 Result<std::vector<ManifestEntry>> ReadEntries(bool only_live);
83
85 Status OpenReader(std::shared_ptr<Schema> projection);
86
88 bool HasPartitionFilter() const;
89
91 bool HasRowFilter() const;
92
94 Result<Evaluator*> GetEvaluator();
95
97 Result<InclusiveMetricsEvaluator*> GetMetricsEvaluator();
98
100 Result<bool> InPartitionSet(const DataFile& file) const;
101
102 // Fields set at construction
103 const std::string manifest_path_;
104 const std::optional<int64_t> manifest_length_;
105 const std::shared_ptr<FileIO> file_io_;
106 const std::shared_ptr<Schema> schema_;
107 const std::shared_ptr<PartitionSpec> spec_;
108 const std::unique_ptr<InheritableMetadata> inheritable_metadata_;
109 std::optional<int64_t> first_row_id_;
110 bool is_committed_;
111
112 // Configuration fields
113 std::vector<std::string> columns_;
114 std::shared_ptr<Expression> part_filter_{True::Instance()};
115 std::shared_ptr<Expression> row_filter_{True::Instance()};
116 std::shared_ptr<PartitionSet> partition_set_;
117 bool case_sensitive_{true};
118 bool drop_stats_{false};
119
120 // Lazy fields
121 std::unique_ptr<Reader> file_reader_;
122 std::shared_ptr<Schema> file_schema_;
123 std::unique_ptr<Evaluator> evaluator_;
124 std::unique_ptr<InclusiveMetricsEvaluator> metrics_evaluator_;
125};
126
129 public:
130 explicit ManifestListReaderImpl(std::unique_ptr<Reader> reader,
131 std::shared_ptr<Schema> schema)
132 : schema_(std::move(schema)), reader_(std::move(reader)) {}
133
134 Result<std::vector<ManifestFile>> Files() const override;
135
136 Result<std::unordered_map<std::string, std::string>> Metadata() const override;
137
138 private:
139 std::shared_ptr<Schema> schema_;
140 std::unique_ptr<Reader> reader_;
141};
142
143enum class ManifestFileField : int32_t {
144 kManifestPath = 0,
145 kManifestLength = 1,
146 kPartitionSpecId = 2,
147 kContent = 3,
148 kSequenceNumber = 4,
149 kMinSequenceNumber = 5,
150 kAddedSnapshotId = 6,
151 kAddedFilesCount = 7,
152 kExistingFilesCount = 8,
153 kDeletedFilesCount = 9,
154 kAddedRowsCount = 10,
155 kExistingRowsCount = 11,
156 kDeletedRowsCount = 12,
157 kPartitionFieldSummary = 13,
158 kKeyMetadata = 14,
159 kFirstRowId = 15,
160 // kNextUnusedId is the placeholder for the next unused index.
161 // Always keep this as the last index when adding new fields.
162 kNextUnusedId = 16,
163};
164
165Result<ManifestFileField> ManifestFileFieldFromIndex(int32_t index);
166
167} // namespace iceberg
Read manifest files from a manifest list file.
Definition manifest_reader_internal.h:128
Result< std::vector< ManifestFile > > Files() const override
Read all manifest files in the manifest list file.
Definition manifest_reader.cc:958
Result< std::unordered_map< std::string, std::string > > Metadata() const override
Get the metadata of the manifest list file.
Definition manifest_reader.cc:978
Read manifest files from a manifest list file.
Definition manifest_reader.h:134
Read manifest entries from a manifest file.
Definition manifest_reader_internal.h:45
ManifestReader & Select(const std::vector< std::string > &columns) override
Select specific columns of data file to read from the manifest entries.
Definition manifest_reader.cc:744
ManifestReader & FilterPartitions(std::shared_ptr< Expression > expr) override
Filter manifest entries by partition filter.
Definition manifest_reader.cc:749
ManifestReader & CaseSensitive(bool case_sensitive) override
Set case sensitivity for column name matching.
Definition manifest_reader.cc:765
Result< std::vector< ManifestEntry > > LiveEntries() override
Read only live (non-deleted) manifest entries.
Definition manifest_reader.cc:861
ManifestReader & FilterRows(std::shared_ptr< Expression > expr) override
Filter manifest entries by row-level filter.
Definition manifest_reader.cc:760
Result< std::vector< ManifestEntry > > Entries() override
Read all manifest entries in the manifest file.
Definition manifest_reader.cc:857
ManifestReader & TryDropStats() override
Try to drop stats from returned DataFile objects.
Definition manifest_reader.cc:770
Read manifest entries from a manifest file.
Definition manifest_reader.h:39
static const std::shared_ptr< True > & Instance()
Returns the singleton instance.
Definition expression.cc:32
DataFile carries data file path, partition tuple, metrics, ...
Definition manifest_entry.h:62