Skip to content

Commit 8a3cab6

Browse files
committed
feat(inspect): Add base class for metadata table support
1 parent cd93b99 commit 8a3cab6

11 files changed

Lines changed: 743 additions & 0 deletions

src/iceberg/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ set(ICEBERG_SOURCES
4242
expression/term.cc
4343
file_reader.cc
4444
file_writer.cc
45+
inspect/history_table.cc
46+
inspect/metadata_table_factory.cc
47+
inspect/snapshots_table.cc
4548
inheritable_metadata.cc
4649
json_serde.cc
4750
location_provider.cc
@@ -57,6 +60,7 @@ set(ICEBERG_SOURCES
5760
manifest/v2_metadata.cc
5861
manifest/v3_metadata.cc
5962
metadata_columns.cc
63+
inspect/metadata_table.cc
6064
metrics_config.cc
6165
name_mapping.cc
6266
partition_field.cc
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
#include "iceberg/inspect/history_table.h"
21+
22+
#include <memory>
23+
#include <utility>
24+
25+
#include "iceberg/inspect/metadata_table.h"
26+
#include "iceberg/schema.h"
27+
#include "iceberg/schema_field.h"
28+
#include "iceberg/table_identifier.h"
29+
#include "iceberg/type.h"
30+
31+
namespace iceberg {
32+
33+
HistoryTable::HistoryTable(std::shared_ptr<Table> table)
34+
: BaseMetadataTable(table, CreateName(table->name()), CreateSchema()) {}
35+
36+
HistoryTable::~HistoryTable() = default;
37+
38+
std::shared_ptr<Schema> HistoryTable::CreateSchema() {
39+
return std::make_shared<Schema>(
40+
std::vector<SchemaField>{
41+
SchemaField::MakeRequired(1, "made_current_at", int64()),
42+
SchemaField::MakeRequired(2, "snapshot_id", int64()),
43+
SchemaField::MakeOptional(3, "parent_id", int64()),
44+
SchemaField::MakeRequired(4, "is_current_ancestor", boolean())},
45+
1);
46+
}
47+
48+
TableIdentifier HistoryTable::CreateName(const TableIdentifier& source_name) {
49+
return TableIdentifier{source_name.ns, source_name.name + ".history"};
50+
}
51+
52+
Result<std::shared_ptr<HistoryTable>> HistoryTable::Make(std::shared_ptr<Table> table) {
53+
return std::shared_ptr<HistoryTable>(new HistoryTable(table));
54+
}
55+
56+
} // namespace iceberg
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
22+
#include <memory>
23+
24+
#include "iceberg/iceberg_export.h"
25+
#include "iceberg/inspect/metadata_table.h"
26+
#include "iceberg/result.h"
27+
#include "iceberg/table.h"
28+
29+
namespace iceberg {
30+
31+
/// \brief History metadata table
32+
///
33+
/// History is based on the table's snapshot log, which logs each update
34+
/// to the table's current snapshot. Each row has columns:
35+
/// - made_current_at (long, timestamp)
36+
/// - snapshot_id (long)
37+
/// - parent_id (long, optional)
38+
/// - is_current_ancestor (bool)
39+
class ICEBERG_EXPORT HistoryTable : public BaseMetadataTable {
40+
public:
41+
/// \brief Create a HistoryTable from table metadata
42+
///
43+
/// \param[in] table The source table
44+
/// \return A HistoryTable instance or error status
45+
static Result<std::shared_ptr<HistoryTable>> Make(std::shared_ptr<Table> table);
46+
47+
~HistoryTable() override;
48+
49+
private:
50+
HistoryTable(std::shared_ptr<Table> table);
51+
52+
std::shared_ptr<Schema> CreateSchema();
53+
54+
TableIdentifier CreateName(const TableIdentifier& source_name);
55+
};
56+
57+
} // namespace iceberg
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
#include "iceberg/inspect/metadata_table.h"
21+
22+
#include <memory>
23+
#include <string>
24+
#include <utility>
25+
26+
#include "iceberg/file_io.h"
27+
#include "iceberg/schema.h"
28+
#include "iceberg/schema_field.h"
29+
#include "iceberg/table_identifier.h"
30+
#include "iceberg/table_metadata.h"
31+
#include "iceberg/table_scan.h"
32+
#include "iceberg/type.h"
33+
#include "iceberg/util/uuid.h"
34+
35+
namespace iceberg {
36+
37+
BaseMetadataTable::BaseMetadataTable(std::shared_ptr<Table> source_table,
38+
TableIdentifier identifier,
39+
std::shared_ptr<Schema> schema)
40+
: Table(identifier, source_table->metadata(),
41+
std::string(source_table->metadata_file_location()), source_table->io(),
42+
source_table->catalog()),
43+
source_table_(std::move(source_table)),
44+
schema_(schema) {
45+
uuid_ = Uuid::GenerateV4().ToString();
46+
schemas_[schema->schema_id()] = schema;
47+
}
48+
49+
BaseMetadataTable::~BaseMetadataTable() = default;
50+
51+
Status BaseMetadataTable::Refresh() {
52+
return NotSupported("Cannot refresh a metadata table");
53+
}
54+
55+
Result<std::unique_ptr<TableScanBuilder>> BaseMetadataTable::NewScan() const {
56+
return NotSupported("TODO: Scanning metadata tables is not yet supported");
57+
};
58+
59+
Result<std::shared_ptr<Transaction>> BaseMetadataTable::NewTransaction() {
60+
return NotSupported("Cannot create a transaction for a metadata table");
61+
}
62+
63+
Result<std::shared_ptr<UpdateProperties>> BaseMetadataTable::NewUpdateProperties() {
64+
return NotSupported("Cannot create an update properties for a metadata table");
65+
}
66+
67+
Result<std::shared_ptr<UpdateSchema>> BaseMetadataTable::NewUpdateSchema() {
68+
return NotSupported("Cannot create an update schema for a metadata table");
69+
}
70+
71+
Result<std::shared_ptr<UpdateLocation>> BaseMetadataTable::NewUpdateLocation() {
72+
return NotSupported("Cannot create an update location for a metadata table");
73+
}
74+
75+
Result<std::shared_ptr<UpdatePartitionSpec>> BaseMetadataTable::NewUpdatePartitionSpec() {
76+
return NotSupported("Cannot create an update partition spec for a metadata table");
77+
}
78+
79+
Result<std::shared_ptr<UpdateSortOrder>> BaseMetadataTable::NewUpdateSortOrder() {
80+
return NotSupported("Cannot create an update sort order for a metadata table");
81+
}
82+
83+
Result<std::shared_ptr<ExpireSnapshots>> BaseMetadataTable::NewExpireSnapshots() {
84+
return NotSupported("Cannot create an expire snapshots for a metadata table");
85+
}
86+
87+
} // namespace iceberg

0 commit comments

Comments
 (0)