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+ // / \file iceberg/table_metadata.h
23+ // / Table metadata for Iceberg tables.
24+
25+ #include < map>
26+ #include < string>
27+ #include < vector>
28+
29+ #include " iceberg/iceberg_export.h"
30+ #include " iceberg/type_fwd.h"
31+ #include " iceberg/util/formattable.h"
32+
33+ namespace iceberg {
34+
35+ // / \brief Represents a snapshot log entry
36+ struct ICEBERG_EXPORT SnapshotLogEntry : public util::Formattable {
37+ // / The timestamp in milliseconds of the change
38+ int64_t timestamp_ms;
39+ // / ID of the snapshot
40+ int64_t snapshot_id;
41+
42+ std::string ToString () const override ;
43+ };
44+
45+ // / \brief Represents a metadata log entry
46+ struct ICEBERG_EXPORT MetadataLogEntry : public util::Formattable {
47+ // / The timestamp in milliseconds of the change
48+ int64_t timestamp_ms;
49+ // / Metadata file location
50+ std::string file;
51+
52+ std::string ToString () const override ;
53+ };
54+
55+ // / \brief Represents the metadata for an Iceberg table
56+ // /
57+ // / Note that it only contains table metadata from the spec. Compared to the Java
58+ // / implementation, missing pieces including: 1) Map<Integer,
59+ // / Schema|PartitionSpec|SortOrder> 2) List<MetadataUpdate> 3) Map<Long, Snapshot> 4)
60+ // / Map<String, SnapshotRef>
61+ // /
62+ // / TODO(wgtmac): Implement Equals and ToString once SortOrder and Snapshot are
63+ // / implemented.
64+ struct ICEBERG_EXPORT TableMetadata {
65+ // / An integer version number for the format
66+ int8_t format_version;
67+ // / A UUID that identifies the table
68+ std::string table_uuid;
69+ // / The table's base location
70+ std::string location;
71+ // / The table's highest assigned sequence number
72+ int64_t last_sequence_number;
73+ // / Timestamp in milliseconds from the unix epoch when the table was last updated.
74+ int64_t last_updated_ms;
75+ // / The highest assigned column ID for the table
76+ int32_t last_column_id;
77+ // / A list of schemas
78+ std::vector<std::shared_ptr<Schema>> schemas;
79+ // / ID of the table's current schema
80+ int32_t current_schema_id;
81+ // / A list of partition specs
82+ std::vector<std::shared_ptr<PartitionSpec>> partition_specs;
83+ // / ID of the current partition spec that writers should use by default
84+ int32_t default_spec_id;
85+ // / The highest assigned partition field ID across all partition specs for the table
86+ int32_t last_partition_id;
87+ // / A string to string map of table properties
88+ std::map<std::string, std::string> properties;
89+ // / ID of the current table snapshot
90+ int64_t current_snapshot_id;
91+ // / A list of valid snapshots
92+ std::vector<std::shared_ptr<Snapshot>> snapshots;
93+ // / A list of timestamp and snapshot ID pairs that encodes changes to the current
94+ // / snapshot for the table
95+ std::vector<SnapshotLogEntry> snapshot_log;
96+ // / A list of timestamp and metadata file location pairs that encodes changes to the
97+ // / previous metadata files for the table
98+ std::vector<MetadataLogEntry> metadata_log;
99+ // / A list of sort orders
100+ std::vector<std::shared_ptr<SortOrder>> sort_orders;
101+ // / Default sort order id of the table
102+ int32_t default_sort_order_id;
103+ // / A map of snapshot references
104+ std::map<std::string, std::string> refs;
105+ // / A list of table statistics
106+ std::vector<std::shared_ptr<struct StatisticsFile >> statistics;
107+ // / A list of partition statistics
108+ std::vector<std::shared_ptr<struct PartitionStatisticsFile >> partition_statistics;
109+ // / whether or not to track the creation and updates to rows in the table
110+ bool row_lineage_enabled = false ;
111+ // / A `long` higher than all assigned row IDs
112+ int64_t next_row_id;
113+ };
114+
115+ } // namespace iceberg
0 commit comments