|
| 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/internal/manifest_writer_internal.h |
| 23 | +/// Writer implementation for manifest list files and manifest files. |
| 24 | + |
| 25 | +#include "iceberg/manifest_writer.h" |
| 26 | + |
| 27 | +namespace iceberg { |
| 28 | + |
| 29 | +/// \brief Write manifest entries to a manifest file. |
| 30 | +class ManifestWriterImpl : public ManifestWriter { |
| 31 | + public: |
| 32 | + explicit ManifestWriterImpl(int64_t first_row_id, std::unique_ptr<Writer> writer, |
| 33 | + std::shared_ptr<Schema> schema) |
| 34 | + : schema_(std::move(schema)), writer_(std::move(writer)) {} |
| 35 | + |
| 36 | + private: |
| 37 | + std::shared_ptr<Schema> schema_; |
| 38 | + std::unique_ptr<Writer> writer_; |
| 39 | +}; |
| 40 | + |
| 41 | +/// \brief Write v1 manifest entries to a manifest file. |
| 42 | +class ManifestWriterV1 : public ManifestWriterImpl { |
| 43 | + public: |
| 44 | + explicit ManifestWriterV1(int64_t first_row_id, std::unique_ptr<Writer> writer, |
| 45 | + std::shared_ptr<Schema> schema) |
| 46 | + : ManifestWriterImpl(first_row_id, std::move(writer), std::move(schema)) {} |
| 47 | + |
| 48 | + Status WriteManifestEntry(const ManifestEntry& entry) const override; |
| 49 | + |
| 50 | + Status Close() override; |
| 51 | +}; |
| 52 | + |
| 53 | +/// \brief Write v2 manifest entries to a manifest file. |
| 54 | +class ManifestWriterV2 : public ManifestWriterImpl { |
| 55 | + public: |
| 56 | + explicit ManifestWriterV2(int64_t first_row_id, std::unique_ptr<Writer> writer, |
| 57 | + std::shared_ptr<Schema> schema) |
| 58 | + : ManifestWriterImpl(first_row_id, std::move(writer), std::move(schema)) {} |
| 59 | + |
| 60 | + Status WriteManifestEntry(const ManifestEntry& entry) const override; |
| 61 | + |
| 62 | + Status Close() override; |
| 63 | +}; |
| 64 | + |
| 65 | +/// \brief Write v3 manifest entries to a manifest file. |
| 66 | +class ManifestWriterV3 : public ManifestWriterImpl { |
| 67 | + public: |
| 68 | + explicit ManifestWriterV3(int64_t first_row_id, std::unique_ptr<Writer> writer, |
| 69 | + std::shared_ptr<Schema> schema) |
| 70 | + : ManifestWriterImpl(first_row_id, std::move(writer), std::move(schema)) {} |
| 71 | + |
| 72 | + Status WriteManifestEntry(const ManifestEntry& entry) const override; |
| 73 | + |
| 74 | + Status Close() override; |
| 75 | +}; |
| 76 | + |
| 77 | +/// \brief Write manifest files to a manifest list file. |
| 78 | +class ManifestListWriterImpl : public ManifestListWriter { |
| 79 | + public: |
| 80 | + explicit ManifestListWriterImpl(int64_t snapshot_id, int64_t parent_snapshot_id, |
| 81 | + int64_t sequence_number, int64_t first_row_id, |
| 82 | + std::unique_ptr<Writer> writer, |
| 83 | + std::shared_ptr<Schema> schema) |
| 84 | + : schema_(std::move(schema)), writer_(std::move(writer)) {} |
| 85 | + |
| 86 | + private: |
| 87 | + std::shared_ptr<Schema> schema_; |
| 88 | + std::unique_ptr<Writer> writer_; |
| 89 | +}; |
| 90 | + |
| 91 | +/// \brief Write v1 manifest files to a manifest list file. |
| 92 | +class ManifestListWriterV1 : public ManifestListWriterImpl { |
| 93 | + public: |
| 94 | + explicit ManifestListWriterV1(int64_t snapshot_id, int64_t parent_snapshot_id, |
| 95 | + int64_t sequence_number, int64_t first_row_id, |
| 96 | + std::unique_ptr<Writer> writer, |
| 97 | + std::shared_ptr<Schema> schema) |
| 98 | + : ManifestListWriterImpl(snapshot_id, parent_snapshot_id, sequence_number, |
| 99 | + first_row_id, std::move(writer), std::move(schema)) {} |
| 100 | + |
| 101 | + Status WriteManifestFile(const ManifestFile& file) const override; |
| 102 | + |
| 103 | + Status Close() override; |
| 104 | +}; |
| 105 | + |
| 106 | +/// \brief Write v2 manifest files to a manifest list file. |
| 107 | +class ManifestListWriterV2 : public ManifestListWriterImpl { |
| 108 | + public: |
| 109 | + explicit ManifestListWriterV2(int64_t snapshot_id, int64_t parent_snapshot_id, |
| 110 | + int64_t sequence_number, int64_t first_row_id, |
| 111 | + std::unique_ptr<Writer> writer, |
| 112 | + std::shared_ptr<Schema> schema) |
| 113 | + : ManifestListWriterImpl(snapshot_id, parent_snapshot_id, sequence_number, |
| 114 | + first_row_id, std::move(writer), std::move(schema)) {} |
| 115 | + |
| 116 | + Status WriteManifestFile(const ManifestFile& file) const override; |
| 117 | + |
| 118 | + Status Close() override; |
| 119 | +}; |
| 120 | + |
| 121 | +/// \brief Write v3 manifest files to a manifest list file. |
| 122 | +class ManifestListWriterV3 : public ManifestListWriterImpl { |
| 123 | + public: |
| 124 | + explicit ManifestListWriterV3(int64_t snapshot_id, int64_t parent_snapshot_id, |
| 125 | + int64_t sequence_number, int64_t first_row_id, |
| 126 | + std::unique_ptr<Writer> writer, |
| 127 | + std::shared_ptr<Schema> schema) |
| 128 | + : ManifestListWriterImpl(snapshot_id, parent_snapshot_id, sequence_number, |
| 129 | + first_row_id, std::move(writer), std::move(schema)) {} |
| 130 | + |
| 131 | + Status WriteManifestFile(const ManifestFile& file) const override; |
| 132 | + |
| 133 | + Status Close() override; |
| 134 | +}; |
| 135 | + |
| 136 | +} // namespace iceberg |
0 commit comments