Repository navigation
feat(inspect): capture scan inputs and open snapshot tasks #1120
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
Open
manuzhang
wants to merge
7
commits into
apache:main
Choose a base branch
from
manuzhang:codex/metadata-scan-support-20261115
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+544
−44
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
33c84fb
feat(inspect): capture scan inputs and open snapshot tasks
manuzhang ca715a5
refactor(inspect): reuse SnapshotUtil for reference lookup
manuzhang 800230f
refactor(inspect): share main branch reference check
manuzhang ee69184
docs(inspect): explain snapshot metadata scan ownership
manuzhang d64f4e5
refactor(inspect): centralize metadata scan context validation
manuzhang 0562ede
refactor(inspect): address snapshot scan review feedback
manuzhang e5c816e
test(inspect): avoid private scan classes in metadata tests
manuzhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
| #include <utility> | ||
|
|
||
| #include "iceberg/constants.h" | ||
| #include "iceberg/inspect/metadata_table_util_internal.h" | ||
| #include "iceberg/schema.h" | ||
| #include "iceberg/table_metadata.h" | ||
| #include "iceberg/type.h" | ||
| #include "iceberg/util/macros.h" | ||
| #include "iceberg/util/snapshot_util.h" | ||
|
|
||
| namespace iceberg::internal { | ||
|
|
||
| namespace { | ||
| /// A scan that plans one task for a metadata table's selected snapshot. | ||
| /// | ||
| /// The task retains the captured metadata, schemas, and FileIO so it can outlive the | ||
| /// scan. Table-specific row reading is deferred to the supplied callback when | ||
| /// MetadataScanTaskReader opens the task. | ||
| class SnapshotMetadataScan : public MetadataScan { | ||
| public: | ||
| SnapshotMetadataScan(MetadataScanContext context, | ||
| std::shared_ptr<SnapshotMetadataTask> task) | ||
| : MetadataScan(std::move(context)), task_(std::move(task)) {} | ||
|
|
||
| Result<MetadataScanTaskStreamPtr> PlanTasksStream() const override { | ||
| // Each planning call gets a fresh stream over the same retained task. | ||
| return MetadataScanTaskStream::FromVector({task_}); | ||
| } | ||
|
|
||
| private: | ||
| const std::shared_ptr<MetadataScanTask> task_; | ||
| }; | ||
| } // namespace | ||
|
|
||
| Result<std::unique_ptr<MetadataScan>> MakeSnapshotMetadataScan( | ||
| MetadataScanContext context, std::shared_ptr<FileIO> io, | ||
| SnapshotMetadataTask::ReadRowsFunction read_rows) { | ||
| ICEBERG_ASSIGN_OR_RAISE(auto task, | ||
| SnapshotMetadataTask::Make(context, std::move(io), read_rows)); | ||
| for (const auto& projected : context.projected_schema->fields()) { | ||
| ICEBERG_ASSIGN_OR_RAISE(auto field, | ||
| context.schema->GetFieldById(projected.field_id())); | ||
| ICEBERG_PRECHECK(field.has_value(), "Unknown metadata column: {}", projected.name()); | ||
| if (*field->get().type() != *projected.type()) { | ||
| return NotSupported("Partial projection of metadata column is not supported: {}", | ||
| projected.name()); | ||
| } | ||
| ICEBERG_PRECHECK(!field->get().optional() || projected.optional(), | ||
| "Nullable metadata column cannot be projected as required: {}", | ||
| projected.name()); | ||
| } | ||
| ICEBERG_RETURN_UNEXPECTED( | ||
| ResolveMetadataTableSnapshot(*context.table_metadata, context)); | ||
| return std::make_unique<SnapshotMetadataScan>(std::move(context), std::move(task)); | ||
| } | ||
|
|
||
| Result<std::shared_ptr<Snapshot>> ResolveMetadataTableSnapshot( | ||
| const TableMetadata& metadata, const MetadataScanContext& selection) { | ||
| const bool is_main_ref = SnapshotUtil::IsMainBranch(selection.ref_name); | ||
| if (!is_main_ref) { | ||
| ICEBERG_PRECHECK( | ||
| !selection.snapshot_id.has_value() && !selection.as_of_time_in_millis.has_value(), | ||
| "Cannot combine a snapshot reference with a snapshot ID or timestamp"); | ||
| } | ||
| if (selection.snapshot_id.has_value()) { | ||
| return metadata.SnapshotById(*selection.snapshot_id); | ||
| } | ||
| if (selection.as_of_time_in_millis.has_value()) { | ||
| ICEBERG_ASSIGN_OR_RAISE( | ||
| auto snapshot_id, | ||
| SnapshotUtil::SnapshotIdAsOfTime( | ||
| metadata, TimePointMsFromUnixMs(*selection.as_of_time_in_millis))); | ||
| return metadata.SnapshotById(snapshot_id); | ||
| } | ||
| if (is_main_ref && metadata.current_snapshot_id == kInvalidSnapshotId) { | ||
| return std::shared_ptr<Snapshot>{nullptr}; | ||
| } | ||
| if (!is_main_ref) { | ||
| auto ref = metadata.refs.find(selection.ref_name); | ||
| ICEBERG_PRECHECK(ref != metadata.refs.end(), "Cannot find snapshot reference '{}'", | ||
| selection.ref_name); | ||
| ICEBERG_PRECHECK(ref->second != nullptr, "Snapshot reference '{}' is null", | ||
| selection.ref_name); | ||
| } | ||
| return SnapshotUtil::LatestSnapshot(metadata, selection.ref_name); | ||
| } | ||
|
|
||
| } // namespace iceberg::internal | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do you plan to support multiple tasks in the future? I'm fine with the current implementation but we need to consider parallel task execution and serialization for better performance.