iceberg-cpp
Loading...
Searching...
No Matches
file_reader.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 <cstdint>
26#include <functional>
27#include <memory>
28#include <optional>
29
31#include "iceberg/file_format.h"
32#include "iceberg/result.h"
33#include "iceberg/type_fwd.h"
34#include "iceberg/util/config.h"
35
36namespace iceberg {
37
39class ICEBERG_EXPORT Reader {
40 public:
41 virtual ~Reader() = default;
42 Reader() = default;
43 Reader(const Reader&) = delete;
44 Reader& operator=(const Reader&) = delete;
45
47 virtual Status Open(const ReaderOptions& options) = 0;
48
50 virtual Status Close() = 0;
51
56
59
62};
63
65struct ICEBERG_EXPORT Split {
67 size_t offset;
69 size_t length;
70};
71
72class ICEBERG_EXPORT ReaderProperties : public ConfigBase<ReaderProperties> {
73 public:
74 template <typename T>
75 using Entry = const ConfigBase<ReaderProperties>::Entry<T>;
76
78 inline static Entry<int64_t> kBatchSize{"read.batch-size", 4096};
82 inline static Entry<bool> kAvroSkipDatum{"read.avro.skip-datum", true};
84 inline static Entry<int64_t> kAvroBufferSize{"read.avro.buffer-size", 1024 * 1024};
85
88 const std::unordered_map<std::string, std::string>& properties);
89};
90
92struct ICEBERG_EXPORT ReaderOptions {
94 std::string path;
96 std::optional<size_t> length;
98 std::optional<Split> split;
100 std::shared_ptr<class FileIO> io;
102 std::shared_ptr<class Schema> projection;
105 std::shared_ptr<class Expression> filter;
108 std::shared_ptr<class NameMapping> name_mapping;
110 std::optional<int64_t> first_row_id;
112 std::optional<int64_t> data_sequence_number;
115};
116
118using ReaderFactory = std::function<Result<std::unique_ptr<Reader>>()>;
119
121struct ICEBERG_EXPORT ReaderFactoryRegistry {
123 ReaderFactoryRegistry(FileFormatType format_type, ReaderFactory factory);
124
126 static ReaderFactory& GetFactory(FileFormatType format_type);
127
129 static Result<std::unique_ptr<Reader>> Open(FileFormatType format_type,
130 const ReaderOptions& options);
131};
132
133} // namespace iceberg
Definition config.h:73
Definition config.h:70
Definition file_reader.h:72
static ReaderProperties FromMap(const std::unordered_map< std::string, std::string > &properties)
Create a ReaderProperties instance from a map of key-value pairs.
Base reader class to read data from different file formats.
Definition file_reader.h:39
virtual Result< std::optional< ArrowArray > > Next()=0
Read next data from file.
virtual Result< ArrowSchema > Schema()=0
Get the schema of the data.
virtual Result< std::unordered_map< std::string, std::string > > Metadata()=0
Get the metadata of the file.
virtual Status Open(const ReaderOptions &options)=0
Open the reader.
virtual Status Close()=0
Close the reader.
Provide typed configuration helpers.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:33
std::expected< T, E > Result
Result alias.
Definition result.h:88
std::function< Result< std::unique_ptr< Reader > >()> ReaderFactory
Factory function to create a reader of a specific file format.
Definition file_reader.h:118
Define Result, Status, and error helpers.
Registry of reader factories for different file formats.
Definition file_reader.h:121
static ReaderFactory & GetFactory(FileFormatType format_type)
Get the factory function for a specific file format.
static Result< std::unique_ptr< Reader > > Open(FileFormatType format_type, const ReaderOptions &options)
Open a reader for a specific file format.
ReaderFactoryRegistry(FileFormatType format_type, ReaderFactory factory)
Register a factory function for a specific file format.
Options for creating a reader.
Definition file_reader.h:92
std::optional< int64_t > data_sequence_number
Data sequence number inherited by the manifest entry, if assigned.
Definition file_reader.h:112
std::shared_ptr< class Schema > projection
The projection schema to read from the file. This field is required.
Definition file_reader.h:102
std::shared_ptr< class FileIO > io
FileIO instance to open the file.
Definition file_reader.h:100
std::optional< size_t > length
The total length of the file.
Definition file_reader.h:96
std::string path
The path to the file to read.
Definition file_reader.h:94
std::shared_ptr< class NameMapping > name_mapping
Name mapping for schema evolution compatibility. Used when reading files that may have different fiel...
Definition file_reader.h:108
std::optional< int64_t > first_row_id
First row ID inherited by the data file, if assigned.
Definition file_reader.h:110
ReaderProperties properties
Format-specific or implementation-specific properties.
Definition file_reader.h:114
std::optional< Split > split
The split to read.
Definition file_reader.h:98
std::shared_ptr< class Expression > filter
The filter to apply to the data. Reader implementations may ignore this if the file format does not s...
Definition file_reader.h:105
A split of the file to read.
Definition file_reader.h:65
size_t offset
The offset of the split.
Definition file_reader.h:67
size_t length
The length of the split.
Definition file_reader.h:69