-
Notifications
You must be signed in to change notification settings - Fork 119
feat(inspect): implement streaming SnapshotsTable scans #801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
3b11911
6c112cc
791474e
a5c20c2
ab62d36
6680bf9
69cfbe9
894539e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,46 +20,108 @@ | |
| #pragma once | ||
|
|
||
| /// \file iceberg/inspect/metadata_table.h | ||
| /// \brief Define base APIs for metadata tables. | ||
| /// \brief Base APIs for inspecting Iceberg metadata tables. | ||
|
|
||
| #include <concepts> | ||
| #include <memory> | ||
| #include <string> | ||
| #include <utility> | ||
| #include <variant> | ||
|
|
||
| #include "iceberg/arrow_c_data.h" | ||
| #include "iceberg/iceberg_export.h" | ||
| #include "iceberg/result.h" | ||
| #include "iceberg/table_identifier.h" | ||
| #include "iceberg/type_fwd.h" | ||
| #include "iceberg/util/timepoint.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| /// \brief Base class for Iceberg metadata tables. | ||
| /// \brief Base interface for an Iceberg metadata table. | ||
| class ICEBERG_EXPORT MetadataTable { | ||
| public: | ||
| /// \brief Supported metadata table kinds. | ||
| enum class Kind { | ||
| kSnapshots, | ||
| kHistory, | ||
| }; | ||
|
|
||
| static Result<std::unique_ptr<MetadataTable>> Make(std::shared_ptr<Table> table, | ||
| Kind kind); | ||
| /// \brief Maximum number of rows emitted in each Arrow batch. | ||
| static constexpr int64_t kBatchSize = 1024; | ||
|
|
||
| /// \brief Create a metadata table of the requested concrete type. | ||
| /// | ||
| /// \tparam MetadataTableType Concrete class derived from MetadataTable. | ||
| /// \param table Source table whose metadata will be exposed. | ||
| /// \return The constructed metadata table, or an error. | ||
| template <typename MetadataTableType> | ||
| requires std::derived_from<MetadataTableType, MetadataTable> | ||
| static Result<std::unique_ptr<MetadataTableType>> Make(std::shared_ptr<Table> table) { | ||
| return MetadataTableType::Make(std::move(table)); | ||
| } | ||
|
WZhuo marked this conversation as resolved.
|
||
|
|
||
| virtual ~MetadataTable(); | ||
|
|
||
| /// \brief Return this metadata table's kind. | ||
| virtual Kind kind() const noexcept = 0; | ||
|
|
||
| const TableIdentifier& name() const { return identifier_; } | ||
| /// \brief Return the schema of rows emitted by scans. | ||
| virtual const std::shared_ptr<Schema>& schema() const = 0; | ||
|
|
||
| /// \brief Return the source table whose metadata is exposed. | ||
| const std::shared_ptr<Table>& source_table() const; | ||
|
|
||
| const std::shared_ptr<Schema>& schema() const { return schema_; } | ||
| /// \brief Return whether this metadata table supports time travel. | ||
| virtual bool supports_time_travel() const noexcept; | ||
|
|
||
| const std::shared_ptr<Table>& source_table() const { return source_table_; } | ||
| /// \brief Scan the metadata table without time travel. | ||
| /// | ||
| /// The caller owns the returned stream and must release it with | ||
| /// ArrowArrayStreamRelease. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ArrowArrayStreamRelease is not declared by this repository's Arrow C Data API; callers must invoke the stream's release callback. Please correct the ownership documentation. |
||
| virtual Result<ArrowArrayStream> Scan() = 0; | ||
|
|
||
| protected: | ||
| explicit MetadataTable(std::shared_ptr<Table> source_table, TableIdentifier identifier, | ||
| std::shared_ptr<Schema> schema); | ||
| explicit MetadataTable(std::shared_ptr<Table> source_table); | ||
|
|
||
| private: | ||
| TableIdentifier identifier_; | ||
| std::shared_ptr<Schema> schema_; | ||
| std::shared_ptr<Table> source_table_; | ||
| }; | ||
|
|
||
| /// \brief Snapshot selection parameters for a time-travel scan. | ||
| struct SnapshotSelection { | ||
| /// \brief Select the current snapshot, a snapshot ID, or an as-of timestamp. | ||
| /// | ||
| /// std::monostate selects the current snapshot. | ||
| std::variant<std::monostate, int64_t, TimePointMs> snapshot; | ||
|
|
||
| /// \brief Resolve the snapshot relative to this branch or tag. | ||
| /// | ||
| /// An empty string uses the main branch. | ||
| std::string ref_name; | ||
| }; | ||
|
|
||
| /// \brief Base interface for metadata tables that support time travel. | ||
| class ICEBERG_EXPORT TimeTravelMetadataTable : public MetadataTable { | ||
| public: | ||
| ~TimeTravelMetadataTable() override; | ||
|
|
||
| /// \brief Return true because this interface supports time travel. | ||
| bool supports_time_travel() const noexcept final; | ||
|
|
||
| /// \brief Scan using the current snapshot on the main branch. | ||
| Result<ArrowArrayStream> Scan() final; | ||
|
|
||
| /// \brief Scan using the requested snapshot selection. | ||
| /// | ||
| /// \param snapshot_selection Snapshot ID, timestamp, and optional ref selection. | ||
| /// \return An Arrow stream containing the metadata table rows, or an error. | ||
| Result<ArrowArrayStream> Scan(const SnapshotSelection& snapshot_selection); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it better to remove this extra layer of |
||
|
|
||
| protected: | ||
| explicit TimeTravelMetadataTable(std::shared_ptr<Table> source_table); | ||
|
|
||
| /// \brief Implement a scan for the requested snapshot selection. | ||
| virtual Result<ArrowArrayStream> ScanSnapshot( | ||
| const SnapshotSelection& snapshot_selection) = 0; | ||
| }; | ||
|
|
||
| } // namespace iceberg | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HistoryTable remains constructible, but the new common Scan() API always returns NotSupported here. Java HistoryTable scans table.history() into rows. Please implement a streaming history scan, or keep non-scannable tables out of this interface.