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
35#include "iceberg/result.h"
36#include "iceberg/type_fwd.h"
37
38namespace iceberg::puffin {
39
43class ICEBERG_EXPORT PuffinWriter {
44 public:
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
60
62 Status Finish();
63
65 Status Close();
66
68 const std::vector<BlobMetadata>& written_blobs_metadata() const;
69
72
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
Result< int64_t > FooterSize() const
Get the footer size. Returns error if the footer has not been written.
static Result< std::unique_ptr< PuffinWriter > > Make(std::unique_ptr< OutputFile > output_file, std::unordered_map< std::string, std::string > properties={}, PuffinCompressionCodec default_codec=PuffinCompressionCodec::kNone, bool compress_footer=false)
Create a PuffinWriter for the given output file.
Status Finish()
Finalize the file by writing the footer and closing the stream.
Result< BlobMetadata > Write(const Blob &blob)
Write a blob and return its metadata.
Result< int64_t > FileSize() const
Get the total file size. Returns error if Finish() has not succeeded.
Status Close()
Close the writer, finalizing the file if needed.
const std::vector< BlobMetadata > & written_blobs_metadata() const
Get metadata for all blobs written so far.
Define symbol visibility macros for core Iceberg APIs.
Puffin file metadata, reader, and writer APIs.
Definition file_metadata.h:35
PuffinCompressionCodec
Compression codecs supported by Puffin files.
Definition file_metadata.h:38
std::expected< T, E > Result
Result alias.
Definition result.h:88
Define Result, Status, and error helpers.
A blob in a Puffin file.
Definition file_metadata.h:70