|
| 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/inheritable_metadata.h |
| 23 | +/// Metadata inheritance system for manifest entries. |
| 24 | + |
| 25 | +#include <cstdint> |
| 26 | +#include <memory> |
| 27 | +#include <string> |
| 28 | + |
| 29 | +#include "iceberg/iceberg_export.h" |
| 30 | +#include "iceberg/result.h" |
| 31 | +#include "iceberg/type_fwd.h" |
| 32 | + |
| 33 | +namespace iceberg { |
| 34 | + |
| 35 | +/// \brief Interface for applying inheritable metadata to manifest entries. |
| 36 | +/// |
| 37 | +/// When manifest entries have null values for certain fields (snapshot id, |
| 38 | +/// data sequence number, file sequence number), these values should be inherited |
| 39 | +/// from the manifest file. This interface provides a way to apply such inheritance rules. |
| 40 | +class ICEBERG_EXPORT InheritableMetadata { |
| 41 | + public: |
| 42 | + virtual ~InheritableMetadata() = default; |
| 43 | + |
| 44 | + /// \brief Apply inheritable metadata to a manifest entry. |
| 45 | + /// \param entry The manifest entry to modify. |
| 46 | + /// \return Status indicating success or failure. |
| 47 | + virtual Status Apply(ManifestEntry& entry) = 0; |
| 48 | +}; |
| 49 | + |
| 50 | +/// \brief Base implementation of InheritableMetadata that handles standard inheritance |
| 51 | +/// rules. |
| 52 | +class ICEBERG_EXPORT BaseInheritableMetadata : public InheritableMetadata { |
| 53 | + public: |
| 54 | + /// \brief Constructor for base inheritable metadata. |
| 55 | + /// \param spec_id Partition spec ID from the manifest. |
| 56 | + /// \param snapshot_id Snapshot ID from the manifest. |
| 57 | + /// \param sequence_number Sequence number from the manifest. |
| 58 | + /// \param manifest_location Path to the manifest file. |
| 59 | + BaseInheritableMetadata(int32_t spec_id, int64_t snapshot_id, int64_t sequence_number, |
| 60 | + std::string manifest_location); |
| 61 | + |
| 62 | + Status Apply(ManifestEntry& entry) override; |
| 63 | + |
| 64 | + private: |
| 65 | + int32_t spec_id_; |
| 66 | + int64_t snapshot_id_; |
| 67 | + int64_t sequence_number_; |
| 68 | + std::string manifest_location_; |
| 69 | +}; |
| 70 | + |
| 71 | +/// \brief Empty implementation that applies no inheritance. |
| 72 | +class ICEBERG_EXPORT EmptyInheritableMetadata : public InheritableMetadata { |
| 73 | + public: |
| 74 | + Status Apply(ManifestEntry& entry) override; |
| 75 | +}; |
| 76 | + |
| 77 | +/// \brief Metadata inheritance for copying manifests before commit. |
| 78 | +class ICEBERG_EXPORT CopyInheritableMetadata : public InheritableMetadata { |
| 79 | + public: |
| 80 | + /// \brief Constructor for copy metadata. |
| 81 | + /// \param snapshot_id The snapshot ID to use for copying. |
| 82 | + explicit CopyInheritableMetadata(int64_t snapshot_id); |
| 83 | + |
| 84 | + Status Apply(ManifestEntry& entry) override; |
| 85 | + |
| 86 | + private: |
| 87 | + int64_t snapshot_id_; |
| 88 | +}; |
| 89 | + |
| 90 | +/// \brief Factory for creating InheritableMetadata instances. |
| 91 | +class ICEBERG_EXPORT InheritableMetadataFactory { |
| 92 | + public: |
| 93 | + /// \brief Create an empty metadata instance that applies no inheritance. |
| 94 | + static Result<std::unique_ptr<InheritableMetadata>> Empty(); |
| 95 | + |
| 96 | + /// \brief Create metadata instance from a manifest file. |
| 97 | + /// \param manifest The manifest file to extract metadata from. |
| 98 | + /// \return Inheritable metadata based on the manifest. |
| 99 | + static Result<std::unique_ptr<InheritableMetadata>> FromManifest( |
| 100 | + const ManifestFile& manifest); |
| 101 | + |
| 102 | + /// \brief Create metadata instance for rewriting a manifest before commit. |
| 103 | + /// \param snapshot_id The snapshot ID for the copy operation. |
| 104 | + /// \return Inheritable metadata for copying. |
| 105 | + static Result<std::unique_ptr<InheritableMetadata>> ForCopy(int64_t snapshot_id); |
| 106 | + |
| 107 | + private: |
| 108 | + InheritableMetadataFactory() = default; |
| 109 | +}; |
| 110 | + |
| 111 | +} // namespace iceberg |
0 commit comments