-
Notifications
You must be signed in to change notification settings - Fork 107
feat(inspect): Add base class for metadata table support #607
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
Draft
All-less
wants to merge
6
commits into
apache:main
Choose a base branch
from
All-less:metadata-table
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.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2a5eed1
feat(inspect): Add base class for metadata table support
All-less 0df25ec
Update MetadataTable to inherit from StaticTable
All-less fc89ecf
Update build files to include MetadataTable
All-less 42bcaf8
Remove unused CreateSchema definitions
All-less 651ab7f
Update Metadata creation to return unique_ptr
All-less 0299583
Refactor MetadataTable to use separate TableMetadata and unified entr…
All-less 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # 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. | ||
|
|
||
| iceberg_install_all_headers(iceberg/inspect) |
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,56 @@ | ||
| /* | ||
| * 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 "iceberg/inspect/history_table.h" | ||
|
|
||
| #include <memory> | ||
| #include <utility> | ||
|
|
||
| #include "iceberg/inspect/metadata_table.h" | ||
| #include "iceberg/schema.h" | ||
| #include "iceberg/schema_field.h" | ||
| #include "iceberg/table_identifier.h" | ||
| #include "iceberg/type.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| HistoryTable::HistoryTable(std::shared_ptr<Table> table) | ||
| : MetadataTable(table, CreateName(table->name())) {} | ||
|
|
||
| HistoryTable::~HistoryTable() = default; | ||
|
|
||
| std::shared_ptr<Schema> HistoryTable::GetSchema() const { | ||
| return std::make_shared<Schema>( | ||
| std::vector<SchemaField>{ | ||
| SchemaField::MakeRequired(1, "made_current_at", timestamp_tz()), | ||
| SchemaField::MakeRequired(2, "snapshot_id", int64()), | ||
| SchemaField::MakeOptional(3, "parent_id", int64()), | ||
| SchemaField::MakeRequired(4, "is_current_ancestor", boolean())}, | ||
| 1); | ||
| } | ||
|
|
||
| TableIdentifier HistoryTable::CreateName(const TableIdentifier& source_name) { | ||
| return TableIdentifier{source_name.ns, source_name.name + ".history"}; | ||
| } | ||
|
|
||
| Result<std::unique_ptr<HistoryTable>> HistoryTable::Make(std::shared_ptr<Table> table) { | ||
| return std::unique_ptr<HistoryTable>(new HistoryTable(table)); | ||
| } | ||
|
|
||
| } // namespace iceberg |
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,59 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <memory> | ||
|
|
||
| #include "iceberg/iceberg_export.h" | ||
| #include "iceberg/inspect/metadata_table.h" | ||
| #include "iceberg/result.h" | ||
| #include "iceberg/table.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| /// \brief History metadata table | ||
| /// | ||
| /// History is based on the table's snapshot log, which logs each update | ||
| /// to the table's current snapshot. Each row has columns: | ||
| /// - made_current_at (long, timestamp) | ||
| /// - snapshot_id (long) | ||
| /// - parent_id (long, optional) | ||
| /// - is_current_ancestor (bool) | ||
| class ICEBERG_EXPORT HistoryTable : public MetadataTable { | ||
| public: | ||
| /// \brief Create a HistoryTable from table metadata | ||
| /// | ||
| /// \param[in] table The source table | ||
| /// \return A HistoryTable instance or error status | ||
| static Result<std::unique_ptr<HistoryTable>> Make(std::shared_ptr<Table> table); | ||
|
|
||
| ~HistoryTable() override; | ||
|
|
||
| MetadataTableType type() const noexcept override { return MetadataTableType::kHistory; } | ||
|
|
||
| std::shared_ptr<Schema> GetSchema() const override; | ||
|
|
||
| private: | ||
| explicit HistoryTable(std::shared_ptr<Table> table); | ||
|
|
||
| TableIdentifier CreateName(const TableIdentifier& source_name); | ||
| }; | ||
|
|
||
| } // namespace iceberg |
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,25 @@ | ||
| # 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. | ||
|
|
||
| install_headers( | ||
| [ | ||
| 'history_table.h', | ||
| 'metadata_table.h', | ||
| 'snapshots_table.h', | ||
| ], | ||
| subdir: 'iceberg/inspect', | ||
| ) |
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,95 @@ | ||
| /* | ||
| * 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 "iceberg/inspect/metadata_table.h" | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
| #include <utility> | ||
|
|
||
| #include "iceberg/file_io.h" | ||
| #include "iceberg/inspect/history_table.h" | ||
| #include "iceberg/inspect/snapshots_table.h" | ||
| #include "iceberg/partition_spec.h" | ||
| #include "iceberg/schema.h" | ||
| #include "iceberg/schema_field.h" | ||
| #include "iceberg/sort_order.h" | ||
| #include "iceberg/table_identifier.h" | ||
| #include "iceberg/table_metadata.h" | ||
| #include "iceberg/table_properties.h" | ||
| #include "iceberg/table_scan.h" | ||
| #include "iceberg/type.h" | ||
| #include "iceberg/type_fwd.h" | ||
| #include "iceberg/util/uuid.h" | ||
|
|
||
| namespace iceberg { | ||
|
|
||
| MetadataTable::MetadataTable(std::shared_ptr<Table> source_table, | ||
| TableIdentifier identifier) | ||
| : StaticTable(identifier, source_table->metadata(), | ||
| std::string(source_table->metadata_file_location()), source_table->io(), | ||
| source_table->catalog()), | ||
| source_table_(std::move(source_table)) { | ||
| auto schema = GetSchema(); | ||
| if (!schema) { | ||
| schema = std::make_shared<Schema>(std::vector<SchemaField>{}, 1); | ||
| } | ||
|
|
||
| auto builder = | ||
| TableMetadataBuilder::BuildFromEmpty(TableMetadata::kDefaultTableFormatVersion); | ||
| auto result = builder->AssignUUID(Uuid::GenerateV4().ToString()) | ||
| .SetLocation(std::string(source_table_->location())) | ||
| .SetCurrentSchema(schema, schema->schema_id()) | ||
| .SetDefaultSortOrder(SortOrder::Unsorted()) | ||
| .SetDefaultPartitionSpec(PartitionSpec::Unpartitioned()) | ||
| .SetProperties({}) | ||
| .Build(); | ||
|
|
||
| if (!result.has_value()) { | ||
| // If metadata building fails, keep the original metadata from source_table | ||
| return; | ||
| } | ||
|
|
||
| std::shared_ptr<TableMetadata> built_metadata = std::move(result.value()); | ||
|
|
||
| metadata_ = built_metadata; | ||
| metadata_cache_ = std::make_unique<TableMetadataCache>(metadata_.get()); | ||
| } | ||
|
|
||
| MetadataTable::~MetadataTable() = default; | ||
|
|
||
| Status MetadataTable::Refresh() { return source_table_->Refresh(); } | ||
|
|
||
| Result<std::unique_ptr<TableScanBuilder>> MetadataTable::NewScan() const { | ||
| return NotSupported("TODO: Scanning metadata tables is not yet supported"); | ||
| }; | ||
|
|
||
| Result<std::unique_ptr<MetadataTable>> MetadataTableFactory::CreateMetadataTable( | ||
| std::shared_ptr<Table> table, MetadataTableType type) { | ||
| switch (type) { | ||
| case MetadataTableType::kSnapshots: | ||
| return SnapshotsTable::Make(table); | ||
| case MetadataTableType::kHistory: | ||
| return HistoryTable::Make(table); | ||
| } | ||
|
|
||
| return Invalid("Unsupported metadata table type"); | ||
| } | ||
|
|
||
| } // namespace iceberg |
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.
Uh oh!
There was an error while loading. Please reload this page.