iceberg-cpp
Loading...
Searching...
No Matches
puffin_writer.h
Go to the documentation of this file.
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
24
25#include <cstddef>
26#include <cstdint>
27#include <memory>
28#include <span>
29#include <string>
30#include <unordered_map>
31#include <vector>
32
33#include "iceberg/iceberg_data_export.h"
35#include "iceberg/result.h"
36#include "iceberg/type_fwd.h"
37
38namespace iceberg::puffin {
39
43class ICEBERG_DATA_EXPORT PuffinWriter {
44 public:
50 static Result<std::unique_ptr<PuffinWriter>> Make(
51 std::unique_ptr<OutputFile> output_file,
52 std::unordered_map<std::string, std::string> properties = {},
53 PuffinCompressionCodec default_codec = PuffinCompressionCodec::kNone,
54 bool compress_footer = false);
55
57
59 Result<BlobMetadata> Write(const Blob& blob);
60
62 Status Finish();
63
65 Status Close();
66
68 const std::vector<BlobMetadata>& written_blobs_metadata() const;
69
71 Result<int64_t> FooterSize() const;
72
74 Result<int64_t> FileSize() const;
75
76 private:
77 PuffinWriter(std::unique_ptr<PositionOutputStream> stream,
78 std::unordered_map<std::string, std::string> properties,
79 PuffinCompressionCodec default_codec, bool compress_footer);
80
81 Status WriteBytes(std::span<const std::byte> data);
82 Status WriteHeader();
83 Status WriteMagic();
84
86 std::unique_ptr<PositionOutputStream> stream_;
88 std::unordered_map<std::string, std::string> properties_;
90 const PuffinCompressionCodec default_codec_;
92 const bool compress_footer_;
94 std::vector<BlobMetadata> written_blobs_metadata_;
96 bool header_written_ = false;
98 bool footer_written_ = false;
100 bool finished_ = false;
102 int64_t footer_size_ = -1;
104 int64_t file_size_ = -1;
105};
106
107} // namespace iceberg::puffin
Writer for Puffin files.
Definition puffin_writer.h:43
PuffinCompressionCodec
Compression codecs supported by Puffin files.
Definition file_metadata.h:38
A blob in a Puffin file.
Definition file_metadata.h:70