Skip to content

Commit 412f6a4

Browse files
HuaHuaYwgtmac
authored andcommitted
feat: implement merge multiple DVs
1 parent 330de84 commit 412f6a4

14 files changed

Lines changed: 501 additions & 13 deletions

src/iceberg/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ set(ICEBERG_SOURCES
2424
catalog/memory/in_memory_catalog.cc
2525
catalog/session_catalog.cc
2626
catalog/session_context.cc
27+
puffin_dv_io.cc
2728
delete_file_index.cc
2829
expression/aggregate.cc
2930
expression/binder.cc
@@ -196,6 +197,7 @@ set(ICEBERG_DATA_SOURCES
196197
data/data_writer.cc
197198
data/delete_filter.cc
198199
data/delete_loader.cc
200+
data/puffin_dv_register.cc
199201
data/deletion_vector_writer.cc
200202
data/dv_util.cc
201203
data/equality_delete_writer.cc

src/iceberg/data/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ install_headers(
2020
'data_writer.h',
2121
'delete_filter.h',
2222
'delete_loader.h',
23+
'puffin_dv_register.h',
2324
'deletion_vector_writer.h',
2425
'equality_delete_writer.h',
2526
'file_scan_task_reader.h',
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
#include "iceberg/data/puffin_dv_register.h"
21+
22+
#include <optional>
23+
#include <string_view>
24+
#include <utility>
25+
26+
#include "iceberg/data/deletion_vector_writer.h"
27+
#include "iceberg/data/dv_util_internal.h"
28+
#include "iceberg/deletes/position_delete_index.h"
29+
#include "iceberg/manifest/manifest_entry.h"
30+
#include "iceberg/util/macros.h"
31+
32+
namespace iceberg {
33+
namespace {
34+
35+
class DataPuffinDVIO final : public PuffinDVIO {
36+
public:
37+
Result<std::vector<std::shared_ptr<DataFile>>> MergeAndWriteDVs(
38+
std::span<const DeletionVectorMergeGroup> groups, std::string_view output_path,
39+
const std::shared_ptr<FileIO>& io) override {
40+
if (groups.empty()) {
41+
return std::vector<std::shared_ptr<DataFile>>{};
42+
}
43+
44+
ICEBERG_ASSIGN_OR_RAISE(
45+
auto writer,
46+
DeletionVectorWriter::Make(DeletionVectorWriterOptions{
47+
.path = std::string(output_path),
48+
.io = io,
49+
.load_previous_deletes = [](std::string_view)
50+
-> Result<std::optional<PositionDeleteIndex>> { return std::nullopt; }}));
51+
52+
for (const auto& group : groups) {
53+
PositionDeleteIndex merged;
54+
for (const auto& delete_file : group.delete_files) {
55+
ICEBERG_ASSIGN_OR_RAISE(auto index, DVUtil::ReadDV(delete_file, io));
56+
merged.Merge(index);
57+
}
58+
ICEBERG_RETURN_UNEXPECTED(writer->Delete(group.referenced_data_file, merged,
59+
group.spec, group.partition));
60+
}
61+
62+
ICEBERG_RETURN_UNEXPECTED(writer->Close());
63+
ICEBERG_ASSIGN_OR_RAISE(auto metadata, writer->Metadata());
64+
return std::move(metadata.data_files);
65+
}
66+
};
67+
68+
} // namespace
69+
70+
std::shared_ptr<PuffinDVIO> MakePuffinDVIO() {
71+
return std::make_shared<DataPuffinDVIO>();
72+
}
73+
74+
void RegisterPuffinDVIO() {
75+
static PuffinDVIORegistry registry(
76+
[]() -> Result<std::shared_ptr<PuffinDVIO>> { return MakePuffinDVIO(); });
77+
}
78+
79+
} // namespace iceberg
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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/data/puffin_dv_register.h
23+
/// Puffin deletion vector I/O registration.
24+
25+
#include <memory>
26+
27+
#include "iceberg/iceberg_data_export.h"
28+
#include "iceberg/puffin_dv_io.h"
29+
30+
namespace iceberg {
31+
32+
ICEBERG_DATA_EXPORT std::shared_ptr<PuffinDVIO> MakePuffinDVIO();
33+
34+
ICEBERG_DATA_EXPORT void RegisterPuffinDVIO();
35+
36+
} // namespace iceberg

src/iceberg/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ iceberg_sources = files(
127127
'partition_field.cc',
128128
'partition_spec.cc',
129129
'partition_summary.cc',
130+
'puffin_dv_io.cc',
130131
'row/arrow_array_wrapper.cc',
131132
'row/manifest_wrapper.cc',
132133
'row/partition_values.cc',
@@ -203,6 +204,7 @@ iceberg_data_sources = files(
203204
'data/equality_delete_writer.cc',
204205
'data/file_scan_task_reader.cc',
205206
'data/position_delete_writer.cc',
207+
'data/puffin_dv_register.cc',
206208
'data/writer.cc',
207209
'deletes/position_delete_index.cc',
208210
'deletes/position_delete_range_consumer.cc',

src/iceberg/puffin_dv_io.cc

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
#include "iceberg/puffin_dv_io.h"
21+
22+
#include <utility>
23+
24+
#include "iceberg/util/macros.h"
25+
26+
namespace iceberg {
27+
namespace {
28+
29+
PuffinDVIOFactory GetNotImplementedFactory() {
30+
return []() -> Result<std::shared_ptr<PuffinDVIO>> {
31+
return NotImplemented("Missing Puffin DV I/O factory");
32+
};
33+
}
34+
35+
} // namespace
36+
37+
PuffinDVIO::~PuffinDVIO() = default;
38+
39+
PuffinDVIORegistry::PuffinDVIORegistry(PuffinDVIOFactory factory) {
40+
GetFactory() = std::move(factory);
41+
}
42+
43+
PuffinDVIOFactory& PuffinDVIORegistry::GetFactory() {
44+
static auto* factory = new PuffinDVIOFactory(GetNotImplementedFactory());
45+
return *factory;
46+
}
47+
48+
Result<std::vector<std::shared_ptr<DataFile>>> PuffinDVIORegistry::MergeAndWriteDVs(
49+
std::span<const DeletionVectorMergeGroup> groups, std::string_view output_path,
50+
const std::shared_ptr<FileIO>& io) {
51+
ICEBERG_ASSIGN_OR_RAISE(auto dv_io, GetFactory()());
52+
ICEBERG_PRECHECK(dv_io != nullptr, "Puffin DV I/O factory returned null");
53+
return dv_io->MergeAndWriteDVs(groups, output_path, io);
54+
}
55+
56+
} // namespace iceberg

src/iceberg/puffin_dv_io.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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/puffin_dv_io.h
23+
/// Deletion vector merge hooks.
24+
25+
#include <functional>
26+
#include <memory>
27+
#include <span>
28+
#include <string>
29+
#include <string_view>
30+
#include <vector>
31+
32+
#include "iceberg/iceberg_export.h"
33+
#include "iceberg/result.h"
34+
#include "iceberg/row/partition_values.h"
35+
#include "iceberg/type_fwd.h"
36+
37+
namespace iceberg {
38+
39+
struct ICEBERG_EXPORT DeletionVectorMergeGroup {
40+
std::string referenced_data_file;
41+
std::vector<std::shared_ptr<DataFile>> delete_files;
42+
std::shared_ptr<PartitionSpec> spec;
43+
PartitionValues partition;
44+
};
45+
46+
class ICEBERG_EXPORT PuffinDVIO {
47+
public:
48+
virtual ~PuffinDVIO();
49+
50+
virtual Result<std::vector<std::shared_ptr<DataFile>>> MergeAndWriteDVs(
51+
std::span<const DeletionVectorMergeGroup> groups, std::string_view output_path,
52+
const std::shared_ptr<FileIO>& io) = 0;
53+
};
54+
55+
using PuffinDVIOFactory = std::function<Result<std::shared_ptr<PuffinDVIO>>()>;
56+
57+
struct ICEBERG_EXPORT PuffinDVIORegistry {
58+
explicit PuffinDVIORegistry(PuffinDVIOFactory factory);
59+
60+
static PuffinDVIOFactory& GetFactory();
61+
62+
static Result<std::vector<std::shared_ptr<DataFile>>> MergeAndWriteDVs(
63+
std::span<const DeletionVectorMergeGroup> groups, std::string_view output_path,
64+
const std::shared_ptr<FileIO>& io);
65+
};
66+
67+
} // namespace iceberg

0 commit comments

Comments
 (0)