|
| 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 |
0 commit comments