Skip to content

Commit 284b077

Browse files
committed
feat: implement merge multiple DVs
1 parent 6f503f9 commit 284b077

15 files changed

Lines changed: 368 additions & 67 deletions

src/iceberg/CMakeLists.txt

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ set(ICEBERG_SOURCES
2424
catalog/session_catalog.cc
2525
catalog/session_context.cc
2626
delete_file_index.cc
27+
deletes/roaring_position_bitmap.cc
2728
expression/aggregate.cc
2829
expression/binder.cc
2930
expression/evaluator.cc
@@ -75,6 +76,11 @@ set(ICEBERG_SOURCES
7576
partition_field.cc
7677
partition_spec.cc
7778
partition_summary.cc
79+
puffin/file_metadata.cc
80+
puffin/json_serde.cc
81+
puffin/puffin_format.cc
82+
puffin/puffin_reader.cc
83+
puffin/puffin_writer.cc
7884
row/arrow_array_wrapper.cc
7985
row/manifest_wrapper.cc
8086
row/partition_values.cc
@@ -146,23 +152,27 @@ list(APPEND
146152
ICEBERG_STATIC_BUILD_INTERFACE_LIBS
147153
"$<IF:$<BOOL:${NANOARROW_VENDORED}>,nanoarrow::nanoarrow_static,$<IF:$<TARGET_EXISTS:nanoarrow::nanoarrow_static>,nanoarrow::nanoarrow_static,nanoarrow::nanoarrow_shared>>"
148154
nlohmann_json::nlohmann_json
155+
roaring::roaring
149156
spdlog::spdlog
150157
ZLIB::ZLIB)
151158
list(APPEND
152159
ICEBERG_SHARED_BUILD_INTERFACE_LIBS
153160
"$<IF:$<BOOL:${NANOARROW_VENDORED}>,nanoarrow::nanoarrow_static,$<IF:$<TARGET_EXISTS:nanoarrow::nanoarrow_shared>,nanoarrow::nanoarrow_shared,nanoarrow::nanoarrow_static>>"
154161
nlohmann_json::nlohmann_json
162+
roaring::roaring
155163
spdlog::spdlog
156164
ZLIB::ZLIB)
157165
list(APPEND
158166
ICEBERG_STATIC_INSTALL_INTERFACE_LIBS
159167
"$<IF:$<BOOL:${NANOARROW_VENDORED}>,iceberg::nanoarrow_static,$<IF:$<TARGET_EXISTS:nanoarrow::nanoarrow_static>,nanoarrow::nanoarrow_static,nanoarrow::nanoarrow_shared>>"
160168
"$<IF:$<BOOL:${NLOHMANN_JSON_VENDORED}>,iceberg::nlohmann_json,$<IF:$<TARGET_EXISTS:nlohmann_json::nlohmann_json>,nlohmann_json::nlohmann_json,nlohmann_json::nlohmann_json>>"
169+
"$<IF:$<BOOL:${CROARING_VENDORED}>,iceberg::roaring,roaring::roaring>"
161170
"$<IF:$<BOOL:${SPDLOG_VENDORED}>,iceberg::spdlog,spdlog::spdlog>")
162171
list(APPEND
163172
ICEBERG_SHARED_INSTALL_INTERFACE_LIBS
164173
"$<IF:$<BOOL:${NANOARROW_VENDORED}>,iceberg::nanoarrow_static,$<IF:$<TARGET_EXISTS:nanoarrow::nanoarrow_shared>,nanoarrow::nanoarrow_shared,nanoarrow::nanoarrow_static>>"
165174
"$<IF:$<BOOL:${NLOHMANN_JSON_VENDORED}>,iceberg::nlohmann_json,$<IF:$<TARGET_EXISTS:nlohmann_json::nlohmann_json>,nlohmann_json::nlohmann_json,nlohmann_json::nlohmann_json>>"
175+
"$<IF:$<BOOL:${CROARING_VENDORED}>,iceberg::roaring,roaring::roaring>"
166176
"$<IF:$<BOOL:${SPDLOG_VENDORED}>,iceberg::spdlog,spdlog::spdlog>")
167177

168178
add_iceberg_lib(iceberg
@@ -190,33 +200,25 @@ set(ICEBERG_DATA_SOURCES
190200
data/position_delete_writer.cc
191201
data/writer.cc
192202
deletes/position_delete_index.cc
193-
deletes/position_delete_range_consumer.cc
194-
deletes/roaring_position_bitmap.cc
195-
puffin/file_metadata.cc
196-
puffin/json_serde.cc
197-
puffin/puffin_format.cc
198-
puffin/puffin_reader.cc
199-
puffin/puffin_writer.cc)
203+
deletes/position_delete_range_consumer.cc)
200204

201205
set(ICEBERG_DATA_STATIC_BUILD_INTERFACE_LIBS)
202206
set(ICEBERG_DATA_SHARED_BUILD_INTERFACE_LIBS)
203207
set(ICEBERG_DATA_STATIC_INSTALL_INTERFACE_LIBS)
204208
set(ICEBERG_DATA_SHARED_INSTALL_INTERFACE_LIBS)
205209

206210
list(APPEND ICEBERG_DATA_STATIC_BUILD_INTERFACE_LIBS
207-
"$<IF:$<TARGET_EXISTS:iceberg_static>,iceberg_static,iceberg_shared>"
208-
roaring::roaring)
211+
"$<IF:$<TARGET_EXISTS:iceberg_static>,iceberg_static,iceberg_shared>")
209212
list(APPEND ICEBERG_DATA_SHARED_BUILD_INTERFACE_LIBS
210-
"$<IF:$<TARGET_EXISTS:iceberg_shared>,iceberg_shared,iceberg_static>"
211-
roaring::roaring)
213+
"$<IF:$<TARGET_EXISTS:iceberg_shared>,iceberg_shared,iceberg_static>")
212214
list(APPEND
213215
ICEBERG_DATA_STATIC_INSTALL_INTERFACE_LIBS
214216
"$<IF:$<TARGET_EXISTS:iceberg::iceberg_static>,iceberg::iceberg_static,iceberg::iceberg_shared>"
215-
"$<IF:$<BOOL:${CROARING_VENDORED}>,iceberg::roaring,roaring::roaring>")
217+
)
216218
list(APPEND
217219
ICEBERG_DATA_SHARED_INSTALL_INTERFACE_LIBS
218220
"$<IF:$<TARGET_EXISTS:iceberg::iceberg_shared>,iceberg::iceberg_shared,iceberg::iceberg_static>"
219-
"$<IF:$<BOOL:${CROARING_VENDORED}>,iceberg::roaring,roaring::roaring>")
221+
)
220222

221223
add_iceberg_lib(iceberg_data
222224
SOURCES

src/iceberg/deletes/roaring_position_bitmap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include <string>
3030
#include <string_view>
3131

32-
#include "iceberg/iceberg_data_export.h"
32+
#include "iceberg/iceberg_export.h"
3333
#include "iceberg/result.h"
3434

3535
namespace iceberg {
@@ -48,7 +48,7 @@ class PositionDeleteIndex;
4848
/// \note This class is used to represent deletion vectors. The Puffin reader/writer
4949
/// handle adding the additional required framing (length prefix, magic bytes, CRC-32)
5050
/// for `deletion-vector-v1` persistence.
51-
class ICEBERG_DATA_EXPORT RoaringPositionBitmap {
51+
class ICEBERG_EXPORT RoaringPositionBitmap {
5252
public:
5353
/// \brief Maximum supported position (aligned with the Java implementation).
5454
static constexpr int64_t kMaxPosition = 0x7FFFFFFE80000000LL;

src/iceberg/meson.build

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ iceberg_sources = files(
4949
'catalog/session_catalog.cc',
5050
'catalog/session_context.cc',
5151
'delete_file_index.cc',
52+
'deletes/roaring_position_bitmap.cc',
5253
'expression/aggregate.cc',
5354
'expression/binder.cc',
5455
'expression/evaluator.cc',
@@ -100,6 +101,11 @@ iceberg_sources = files(
100101
'partition_field.cc',
101102
'partition_spec.cc',
102103
'partition_summary.cc',
104+
'puffin/file_metadata.cc',
105+
'puffin/json_serde.cc',
106+
'puffin/puffin_format.cc',
107+
'puffin/puffin_reader.cc',
108+
'puffin/puffin_writer.cc',
103109
'row/arrow_array_wrapper.cc',
104110
'row/manifest_wrapper.cc',
105111
'row/partition_values.cc',
@@ -173,12 +179,6 @@ iceberg_data_sources = files(
173179
'data/writer.cc',
174180
'deletes/position_delete_index.cc',
175181
'deletes/position_delete_range_consumer.cc',
176-
'deletes/roaring_position_bitmap.cc',
177-
'puffin/file_metadata.cc',
178-
'puffin/json_serde.cc',
179-
'puffin/puffin_format.cc',
180-
'puffin/puffin_reader.cc',
181-
'puffin/puffin_writer.cc',
182182
)
183183

184184
# CRoaring does not export symbols, so on Windows it must
@@ -193,7 +193,13 @@ nlohmann_json_dep = dependency('nlohmann_json')
193193
spdlog_dep = dependency('spdlog')
194194
zlib_dep = dependency('zlib')
195195

196-
iceberg_deps = [nanoarrow_dep, nlohmann_json_dep, spdlog_dep, zlib_dep]
196+
iceberg_deps = [
197+
nanoarrow_dep,
198+
nlohmann_json_dep,
199+
croaring_dep,
200+
spdlog_dep,
201+
zlib_dep,
202+
]
197203

198204
iceberg_lib = library(
199205
'iceberg',
@@ -219,7 +225,7 @@ iceberg_dep = declare_dependency(
219225
)
220226
meson.override_dependency('iceberg', iceberg_dep)
221227

222-
iceberg_data_deps = [iceberg_dep, croaring_dep]
228+
iceberg_data_deps = [iceberg_dep]
223229
iceberg_data_lib = library(
224230
'iceberg_data',
225231
sources: iceberg_data_sources,

src/iceberg/puffin/file_metadata.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include <unordered_map>
3030
#include <vector>
3131

32-
#include "iceberg/iceberg_data_export.h"
32+
#include "iceberg/iceberg_export.h"
3333
#include "iceberg/result.h"
3434

3535
namespace iceberg::puffin {
@@ -41,12 +41,12 @@ enum class PuffinCompressionCodec {
4141
kZstd,
4242
};
4343

44-
ICEBERG_DATA_EXPORT std::string_view CodecName(PuffinCompressionCodec codec);
44+
ICEBERG_EXPORT std::string_view CodecName(PuffinCompressionCodec codec);
4545

46-
ICEBERG_DATA_EXPORT Result<PuffinCompressionCodec> PuffinCompressionCodecFromName(
46+
ICEBERG_EXPORT Result<PuffinCompressionCodec> PuffinCompressionCodecFromName(
4747
std::string_view codec_name);
4848

49-
ICEBERG_DATA_EXPORT std::string ToString(PuffinCompressionCodec codec);
49+
ICEBERG_EXPORT std::string ToString(PuffinCompressionCodec codec);
5050

5151
/// \brief Standard blob types defined by the Iceberg specification.
5252
struct StandardBlobTypes {
@@ -67,7 +67,7 @@ struct StandardPuffinProperties {
6767
};
6868

6969
/// \brief A blob in a Puffin file.
70-
struct ICEBERG_DATA_EXPORT Blob {
70+
struct ICEBERG_EXPORT Blob {
7171
/// See StandardBlobTypes for known types.
7272
std::string type;
7373
/// Ordered list of field IDs the blob was computed from.
@@ -84,10 +84,10 @@ struct ICEBERG_DATA_EXPORT Blob {
8484
friend bool operator==(const Blob& lhs, const Blob& rhs) = default;
8585
};
8686

87-
ICEBERG_DATA_EXPORT std::string ToString(const Blob& blob);
87+
ICEBERG_EXPORT std::string ToString(const Blob& blob);
8888

8989
/// \brief Metadata about a blob stored in a Puffin file footer.
90-
struct ICEBERG_DATA_EXPORT BlobMetadata {
90+
struct ICEBERG_EXPORT BlobMetadata {
9191
/// See StandardBlobTypes for known types.
9292
std::string type;
9393
/// Ordered list of field IDs the blob was computed from.
@@ -105,16 +105,16 @@ struct ICEBERG_DATA_EXPORT BlobMetadata {
105105
friend bool operator==(const BlobMetadata& lhs, const BlobMetadata& rhs) = default;
106106
};
107107

108-
ICEBERG_DATA_EXPORT std::string ToString(const BlobMetadata& blob_metadata);
108+
ICEBERG_EXPORT std::string ToString(const BlobMetadata& blob_metadata);
109109

110110
/// \brief Metadata about a Puffin file.
111-
struct ICEBERG_DATA_EXPORT FileMetadata {
111+
struct ICEBERG_EXPORT FileMetadata {
112112
std::vector<BlobMetadata> blobs;
113113
std::unordered_map<std::string, std::string> properties;
114114

115115
friend bool operator==(const FileMetadata& lhs, const FileMetadata& rhs) = default;
116116
};
117117

118-
ICEBERG_DATA_EXPORT std::string ToString(const FileMetadata& file_metadata);
118+
ICEBERG_EXPORT std::string ToString(const FileMetadata& file_metadata);
119119

120120
} // namespace iceberg::puffin

src/iceberg/puffin/json_serde_internal.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,30 @@
2727

2828
#include <nlohmann/json_fwd.hpp>
2929

30-
#include "iceberg/iceberg_data_export.h"
30+
#include "iceberg/iceberg_export.h"
3131
#include "iceberg/puffin/type_fwd.h"
3232
#include "iceberg/result.h"
3333

3434
namespace iceberg::puffin {
3535

3636
/// \brief Serialize a BlobMetadata to JSON.
37-
ICEBERG_DATA_EXPORT nlohmann::json ToJson(const BlobMetadata& blob_metadata);
37+
ICEBERG_EXPORT nlohmann::json ToJson(const BlobMetadata& blob_metadata);
3838

3939
/// \brief Deserialize a BlobMetadata from JSON.
40-
ICEBERG_DATA_EXPORT Result<BlobMetadata> BlobMetadataFromJson(const nlohmann::json& json);
40+
ICEBERG_EXPORT Result<BlobMetadata> BlobMetadataFromJson(const nlohmann::json& json);
4141

4242
/// \brief Serialize a FileMetadata to JSON.
43-
ICEBERG_DATA_EXPORT nlohmann::json ToJson(const FileMetadata& file_metadata);
43+
ICEBERG_EXPORT nlohmann::json ToJson(const FileMetadata& file_metadata);
4444

4545
/// \brief Deserialize a FileMetadata from JSON.
46-
ICEBERG_DATA_EXPORT Result<FileMetadata> FileMetadataFromJson(const nlohmann::json& json);
46+
ICEBERG_EXPORT Result<FileMetadata> FileMetadataFromJson(const nlohmann::json& json);
4747

4848
/// \brief Serialize a FileMetadata to a JSON string.
49-
ICEBERG_DATA_EXPORT std::string ToJsonString(const FileMetadata& file_metadata,
50-
bool pretty = false);
49+
ICEBERG_EXPORT std::string ToJsonString(const FileMetadata& file_metadata,
50+
bool pretty = false);
5151

5252
/// \brief Deserialize a FileMetadata from a JSON string.
53-
ICEBERG_DATA_EXPORT Result<FileMetadata> FileMetadataFromJsonString(
53+
ICEBERG_EXPORT Result<FileMetadata> FileMetadataFromJsonString(
5454
std::string_view json_string);
5555

5656
} // namespace iceberg::puffin

src/iceberg/puffin/puffin_format.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
#include <span>
2929
#include <vector>
3030

31-
#include "iceberg/iceberg_data_export.h"
31+
#include "iceberg/iceberg_export.h"
3232
#include "iceberg/puffin/file_metadata.h"
3333
#include "iceberg/result.h"
3434

3535
namespace iceberg::puffin {
3636

3737
/// \brief Puffin file format constants.
38-
struct ICEBERG_DATA_EXPORT PuffinFormat {
38+
struct ICEBERG_EXPORT PuffinFormat {
3939
/// Magic bytes: "PFA1" (Puffin Fratercula arctica, version 1)
4040
static constexpr std::array<uint8_t, 4> kMagicV1 = {0x50, 0x46, 0x41, 0x31};
4141

@@ -63,17 +63,17 @@ enum class PuffinFlag : uint8_t {
6363
};
6464

6565
/// \brief Check if a flag is set in the flags bytes.
66-
ICEBERG_DATA_EXPORT bool IsFlagSet(std::span<const uint8_t, 4> flags, PuffinFlag flag);
66+
ICEBERG_EXPORT bool IsFlagSet(std::span<const uint8_t, 4> flags, PuffinFlag flag);
6767

6868
/// \brief Set a flag in the flags bytes.
69-
ICEBERG_DATA_EXPORT void SetFlag(std::span<uint8_t, 4> flags, PuffinFlag flag);
69+
ICEBERG_EXPORT void SetFlag(std::span<uint8_t, 4> flags, PuffinFlag flag);
7070

7171
/// \brief Compress data using the specified codec.
72-
ICEBERG_DATA_EXPORT Result<std::vector<std::byte>> Compress(
73-
PuffinCompressionCodec codec, std::span<const std::byte> input);
72+
ICEBERG_EXPORT Result<std::vector<std::byte>> Compress(PuffinCompressionCodec codec,
73+
std::span<const std::byte> input);
7474

7575
/// \brief Decompress data using the specified codec.
76-
ICEBERG_DATA_EXPORT Result<std::vector<std::byte>> Decompress(
76+
ICEBERG_EXPORT Result<std::vector<std::byte>> Decompress(
7777
PuffinCompressionCodec codec, std::span<const std::byte> input);
7878

7979
} // namespace iceberg::puffin

src/iceberg/puffin/puffin_reader.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#include <utility>
3030
#include <vector>
3131

32-
#include "iceberg/iceberg_data_export.h"
32+
#include "iceberg/iceberg_export.h"
3333
#include "iceberg/puffin/file_metadata.h"
3434
#include "iceberg/result.h"
3535
#include "iceberg/type_fwd.h"
@@ -39,7 +39,7 @@ namespace iceberg::puffin {
3939
/// \brief Reader for Puffin files.
4040
///
4141
/// Reads from an InputFile with seek support for efficient blob access.
42-
class ICEBERG_DATA_EXPORT PuffinReader {
42+
class ICEBERG_EXPORT PuffinReader {
4343
public:
4444
/// \brief Create a PuffinReader for the given input file.
4545
/// \param input_file The input file to read from.

src/iceberg/puffin/puffin_writer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ Status PuffinWriter::Finish() {
152152

153153
ICEBERG_ASSIGN_OR_RAISE(auto end_pos, stream_->Position());
154154
footer_size_ = end_pos - footer_start;
155+
file_size_ = end_pos;
155156
footer_written_ = true;
156157
ICEBERG_RETURN_UNEXPECTED(stream_->Flush());
157158
ICEBERG_RETURN_UNEXPECTED(stream_->Close());
158-
ICEBERG_ASSIGN_OR_RAISE(file_size_, stream_->Position());
159159
finished_ = true;
160160
return {};
161161
}

src/iceberg/puffin/puffin_writer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#include <unordered_map>
3131
#include <vector>
3232

33-
#include "iceberg/iceberg_data_export.h"
33+
#include "iceberg/iceberg_export.h"
3434
#include "iceberg/puffin/file_metadata.h"
3535
#include "iceberg/result.h"
3636
#include "iceberg/type_fwd.h"
@@ -40,7 +40,7 @@ namespace iceberg::puffin {
4040
/// \brief Writer for Puffin files.
4141
///
4242
/// Writes blobs and footer to an OutputFile stream.
43-
class ICEBERG_DATA_EXPORT PuffinWriter {
43+
class ICEBERG_EXPORT PuffinWriter {
4444
public:
4545
/// \brief Create a PuffinWriter for the given output file.
4646
/// \param output_file The output file to write to.

0 commit comments

Comments
 (0)