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