Skip to content

Commit 7324142

Browse files
authored
feat(inspect): add base metadata table interface (#607)
This PR kicks off the implementation of table inspection support. - Add `MetadataTable` class (without scan support for now). - Add `SnapshotsTable` and `HistoryTable` as example impl.
1 parent cc4d35f commit 7324142

17 files changed

Lines changed: 575 additions & 1 deletion

src/iceberg/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ set(ICEBERG_SOURCES
4141
file_io_registry.cc
4242
file_reader.cc
4343
file_writer.cc
44+
inspect/history_table.cc
45+
inspect/metadata_table.cc
46+
inspect/snapshots_table.cc
4447
inheritable_metadata.cc
4548
json_serde.cc
4649
location_provider.cc
@@ -238,6 +241,7 @@ add_subdirectory(puffin)
238241
add_subdirectory(row)
239242
add_subdirectory(update)
240243
add_subdirectory(util)
244+
add_subdirectory(inspect)
241245
add_subdirectory(metrics)
242246

243247
if(ICEBERG_BUILD_BUNDLE)

src/iceberg/inspect/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
iceberg_install_all_headers(iceberg/inspect)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
#include <vector>
25+
26+
#include "iceberg/schema.h"
27+
#include "iceberg/schema_field.h"
28+
#include "iceberg/table.h"
29+
#include "iceberg/table_identifier.h"
30+
#include "iceberg/type.h"
31+
32+
namespace iceberg {
33+
namespace {
34+
35+
std::shared_ptr<Schema> MakeHistoryTableSchema() {
36+
return std::make_shared<Schema>(std::vector<SchemaField>{
37+
SchemaField::MakeRequired(1, "made_current_at", timestamp_tz()),
38+
SchemaField::MakeRequired(2, "snapshot_id", int64()),
39+
SchemaField::MakeOptional(3, "parent_id", int64()),
40+
SchemaField::MakeRequired(4, "is_current_ancestor", boolean())});
41+
}
42+
43+
TableIdentifier MakeHistoryTableName(const TableIdentifier& source_name) {
44+
return TableIdentifier{.ns = source_name.ns, .name = source_name.name + ".history"};
45+
}
46+
47+
} // namespace
48+
49+
HistoryTable::HistoryTable(std::shared_ptr<Table> table)
50+
: MetadataTable(table, MakeHistoryTableName(table->name()),
51+
MakeHistoryTableSchema()) {}
52+
53+
HistoryTable::~HistoryTable() = default;
54+
55+
Result<std::unique_ptr<HistoryTable>> HistoryTable::Make(std::shared_ptr<Table> table) {
56+
if (table == nullptr) [[unlikely]] {
57+
return InvalidArgument("Table cannot be null");
58+
}
59+
return std::unique_ptr<HistoryTable>(new HistoryTable(std::move(table)));
60+
}
61+
62+
} // namespace iceberg
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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/type_fwd.h"
28+
29+
namespace iceberg {
30+
31+
/// \brief History metadata table.
32+
class ICEBERG_EXPORT HistoryTable : public MetadataTable {
33+
public:
34+
static Result<std::unique_ptr<HistoryTable>> Make(std::shared_ptr<Table> table);
35+
36+
~HistoryTable() override;
37+
38+
Kind kind() const noexcept override { return Kind::kHistory; }
39+
40+
private:
41+
explicit HistoryTable(std::shared_ptr<Table> table);
42+
};
43+
44+
} // namespace iceberg

src/iceberg/inspect/meson.build

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
install_headers(
19+
['history_table.h', 'metadata_table.h', 'snapshots_table.h'],
20+
subdir: 'iceberg/inspect',
21+
)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 <utility>
24+
25+
#include "iceberg/inspect/history_table.h"
26+
#include "iceberg/inspect/snapshots_table.h"
27+
28+
namespace iceberg {
29+
30+
MetadataTable::MetadataTable(std::shared_ptr<Table> source_table,
31+
TableIdentifier identifier, std::shared_ptr<Schema> schema)
32+
: identifier_(std::move(identifier)),
33+
schema_(std::move(schema)),
34+
source_table_(std::move(source_table)) {}
35+
36+
MetadataTable::~MetadataTable() = default;
37+
38+
Result<std::unique_ptr<MetadataTable>> MetadataTable::Make(std::shared_ptr<Table> table,
39+
Kind kind) {
40+
if (table == nullptr) [[unlikely]] {
41+
return InvalidArgument("Table cannot be null");
42+
}
43+
44+
switch (kind) {
45+
case Kind::kSnapshots:
46+
return SnapshotsTable::Make(table);
47+
case Kind::kHistory:
48+
return HistoryTable::Make(table);
49+
}
50+
51+
return NotSupported("Unsupported metadata table type");
52+
}
53+
54+
} // namespace iceberg
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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/result.h"
26+
#include "iceberg/table_identifier.h"
27+
#include "iceberg/type_fwd.h"
28+
29+
namespace iceberg {
30+
31+
/// \brief Base class for Iceberg metadata tables.
32+
class ICEBERG_EXPORT MetadataTable {
33+
public:
34+
enum class Kind {
35+
kSnapshots,
36+
kHistory,
37+
};
38+
39+
static Result<std::unique_ptr<MetadataTable>> Make(std::shared_ptr<Table> table,
40+
Kind kind);
41+
42+
virtual ~MetadataTable();
43+
44+
virtual Kind kind() const noexcept = 0;
45+
46+
const TableIdentifier& name() const { return identifier_; }
47+
48+
const std::shared_ptr<Schema>& schema() const { return schema_; }
49+
50+
const std::shared_ptr<Table>& source_table() const { return source_table_; }
51+
52+
protected:
53+
explicit MetadataTable(std::shared_ptr<Table> source_table, TableIdentifier identifier,
54+
std::shared_ptr<Schema> schema);
55+
56+
private:
57+
TableIdentifier identifier_;
58+
std::shared_ptr<Schema> schema_;
59+
std::shared_ptr<Table> source_table_;
60+
};
61+
62+
} // namespace iceberg
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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/snapshots_table.h"
21+
22+
#include <memory>
23+
#include <utility>
24+
#include <vector>
25+
26+
#include "iceberg/schema.h"
27+
#include "iceberg/schema_field.h"
28+
#include "iceberg/table.h"
29+
#include "iceberg/table_identifier.h"
30+
#include "iceberg/type.h"
31+
32+
namespace iceberg {
33+
namespace {
34+
35+
std::shared_ptr<Schema> MakeSnapshotsTableSchema() {
36+
return std::make_shared<Schema>(std::vector<SchemaField>{
37+
SchemaField::MakeRequired(1, "committed_at", timestamp_tz()),
38+
SchemaField::MakeRequired(2, "snapshot_id", int64()),
39+
SchemaField::MakeOptional(3, "parent_id", int64()),
40+
SchemaField::MakeOptional(4, "operation", string()),
41+
SchemaField::MakeOptional(5, "manifest_list", string()),
42+
SchemaField::MakeOptional(6, "summary",
43+
std::make_shared<iceberg::MapType>(
44+
SchemaField::MakeRequired(7, "key", string()),
45+
SchemaField::MakeRequired(8, "value", string())))});
46+
}
47+
48+
TableIdentifier MakeSnapshotsTableName(const TableIdentifier& source_name) {
49+
return TableIdentifier{.ns = source_name.ns, .name = source_name.name + ".snapshots"};
50+
}
51+
52+
} // namespace
53+
54+
SnapshotsTable::SnapshotsTable(std::shared_ptr<Table> table)
55+
: MetadataTable(table, MakeSnapshotsTableName(table->name()),
56+
MakeSnapshotsTableSchema()) {}
57+
58+
SnapshotsTable::~SnapshotsTable() = default;
59+
60+
Result<std::unique_ptr<SnapshotsTable>> SnapshotsTable::Make(
61+
std::shared_ptr<Table> table) {
62+
if (table == nullptr) [[unlikely]] {
63+
return InvalidArgument("Table cannot be null");
64+
}
65+
return std::unique_ptr<SnapshotsTable>(new SnapshotsTable(std::move(table)));
66+
}
67+
68+
} // namespace iceberg
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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/type_fwd.h"
28+
29+
namespace iceberg {
30+
31+
/// \brief Snapshots metadata table.
32+
class ICEBERG_EXPORT SnapshotsTable : public MetadataTable {
33+
public:
34+
static Result<std::unique_ptr<SnapshotsTable>> Make(std::shared_ptr<Table> table);
35+
36+
~SnapshotsTable() override;
37+
38+
Kind kind() const noexcept override { return Kind::kSnapshots; }
39+
40+
private:
41+
explicit SnapshotsTable(std::shared_ptr<Table> table);
42+
};
43+
44+
} // namespace iceberg

0 commit comments

Comments
 (0)