iceberg-cpp
Loading...
Searching...
No Matches
metadata_scan.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 <memory>
27#include <optional>
28#include <string>
29#include <vector>
30
33#include "iceberg/result.h"
34#include "iceberg/type_fwd.h"
36#include "iceberg/util/stream.h"
37
38namespace iceberg {
39
40using MetadataScanTaskStream = Stream<std::shared_ptr<MetadataScanTask>>;
41using MetadataScanTaskStreamPtr = std::unique_ptr<MetadataScanTaskStream>;
42
43namespace internal {
44
48 std::shared_ptr<const TableMetadata> table_metadata;
49 std::shared_ptr<Schema> schema;
50 std::shared_ptr<Schema> projected_schema;
51 bool case_sensitive = true;
52 std::optional<int64_t> snapshot_id;
53 std::string ref_name;
54 std::optional<int64_t> as_of_time_in_millis;
55};
56
57} // namespace internal
58
60class ICEBERG_EXPORT MetadataScanBuilder : public ErrorCollector {
61 public:
62 ~MetadataScanBuilder() override;
63
66
72 MetadataScanBuilder& Select(const std::vector<std::string>& columns);
73
77 MetadataScanBuilder& Project(std::shared_ptr<Schema> schema);
78
81
83 MetadataScanBuilder& UseSnapshot(int64_t snapshot_id);
84
86 MetadataScanBuilder& UseRef(const std::string& ref);
87
92 MetadataScanBuilder& AsOfTime(int64_t as_of_time_in_millis);
93
98
99 private:
100 explicit MetadataScanBuilder(const MetadataTable& table);
101
102 const MetadataTable* table_;
104};
105
107class ICEBERG_EXPORT MetadataScan {
108 public:
109 virtual ~MetadataScan();
110
113
116
123
124 protected:
126
127 const internal::MetadataScanContext& context() const { return context_; }
128
129 private:
130 const internal::MetadataScanContext context_;
131};
132
133} // namespace iceberg
Base class for collecting errors in the builder pattern.
Definition error_collector.h:99
Configure a scan over captured metadata; the metadata table must outlive it.
Definition metadata_scan.h:60
MetadataScanBuilder & AsOfTime(int64_t as_of_time_in_millis)
Select the latest snapshot at or before this timestamp on the selected ref.
MetadataScanBuilder & CaseSensitive(bool value)
Match column names case-sensitively; enabled by default.
MetadataScanBuilder & UseRef(const std::string &ref)
Select a branch or tag; Build rejects tables without time travel.
MetadataScanBuilder & Project(std::shared_ptr< Schema > schema)
Project whole columns by field ID, optionally reordering them.
static Result< std::unique_ptr< MetadataScanBuilder > > Make(const MetadataTable &table)
Capture the source metadata and schema of a metadata table.
MetadataScanBuilder & Select(const std::vector< std::string > &columns)
Select names using the current CaseSensitive() setting.
MetadataScanBuilder & UseSnapshot(int64_t snapshot_id)
Select a snapshot ID; Build rejects tables without time travel.
Result< std::unique_ptr< MetadataScan > > Build()
Validate the settings and build a scan with its own copy of them.
A metadata scan that plans tasks or reads all of them as Arrow batches.
Definition metadata_scan.h:107
virtual Result< MetadataScanTaskStreamPtr > PlanTasksStream() const =0
Return a fresh task stream; consuming it may report planning errors.
virtual Result< std::vector< std::shared_ptr< MetadataScanTask > > > PlanTasks() const
Collect every task from PlanTasksStream(), preserving planning order.
virtual Result< ArrowArrayStream > ToArrowArrayStream() const
Read every task in planning order as one Arrow stream.
A metadata table backed by a source Iceberg table.
Definition metadata_table.h:60
Definition expected.h:1199
Define symbol visibility macros for core Iceberg APIs.
Core Apache Iceberg C++ APIs.
Definition arrow_io_util.h:34
MetadataTableKind
Iceberg metadata tables exposed by Table::Inspect().
Definition metadata_table.h:40
Define Result, Status, and error helpers.
Pull-based stream interface for fallible, lazily produced values.
Captured metadata and logical settings shared by a builder and its scans.
Definition metadata_scan.h:46