You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "wgtmac (via GitHub)" <gi...@apache.org> on 2026/03/31 05:53:21 UTC
[PR] feat(data): add DeleteLoader for position and equality delete files [iceberg-cpp]
wgtmac opened a new pull request, #610:
URL: https://github.com/apache/iceberg-cpp/pull/610
- LoadPositionDeletes dispatches to LoadPositionDelete (file-based) and LoadDV (deletion vectors, not yet implemented).
- LoadEqualityDeletes reads equality delete files into a StructLikeSet.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat(data): add DeleteLoader for position and equality delete files [iceberg-cpp]
Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac merged PR #610:
URL: https://github.com/apache/iceberg-cpp/pull/610
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat(data): add DeleteLoader for position and equality delete files [iceberg-cpp]
Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #610:
URL: https://github.com/apache/iceberg-cpp/pull/610#discussion_r3031710152
##########
src/iceberg/data/delete_loader.h:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#pragma once
+
+/// \file iceberg/data/delete_loader.h
+/// Loads position and equality delete files into in-memory indexes.
+
+#include <memory>
+#include <span>
+#include <string_view>
+
+#include "iceberg/iceberg_export.h"
+#include "iceberg/result.h"
+#include "iceberg/type_fwd.h"
+#include "iceberg/util/struct_like_set.h"
+
+namespace iceberg {
+
+/// \brief Loads delete files and constructs in-memory delete indexes.
+class ICEBERG_EXPORT DeleteLoader {
+ public:
+ /// \brief Create a DeleteLoader.
+ /// \param io FileIO instance for reading delete files
+ explicit DeleteLoader(std::shared_ptr<FileIO> io);
+
+ ~DeleteLoader();
+
+ /// \brief Load position deletes for a specific data file.
+ ///
+ /// Reads the given position delete files and returns a PositionDeleteIndex
+ /// containing only the positions that apply to the specified data file path.
+ /// Supports both regular position delete files and deletion vectors.
+ ///
+ /// \param delete_files Position delete files to load (must have
+ /// content == Content::kPositionDeletes)
+ /// \param data_file_path Path of the data file to filter positions for
+ /// \return A PositionDeleteIndex with deleted positions for the data file
+ Result<PositionDeleteIndex> LoadPositionDeletes(
+ std::span<const std::shared_ptr<DataFile>> delete_files,
+ std::string_view data_file_path) const;
+
+ /// \brief Load equality deletes into an in-memory set.
+ ///
+ /// \param delete_files Equality delete files to load (must have
+ /// content == Content::kEqualityDeletes)
+ /// \param equality_type The struct type describing the equality columns
+ /// \return A StructLikeSet containing the deleted rows
+ Result<std::unique_ptr<UncheckedStructLikeSet>> LoadEqualityDeletes(
Review Comment:
PositionDeleteIndex is a movable value type, so it can be returned directly by value. UncheckedStructLikeSet contains a `std::pmr::monotonic_buffer_resource`, which is neither copyable nor movable, so it must be heap-allocated and returned via unique_ptr.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat(data): add DeleteLoader for position and equality delete files [iceberg-cpp]
Posted by "gty404 (via GitHub)" <gi...@apache.org>.
gty404 commented on code in PR #610:
URL: https://github.com/apache/iceberg-cpp/pull/610#discussion_r3031184900
##########
src/iceberg/data/delete_loader.h:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#pragma once
+
+/// \file iceberg/data/delete_loader.h
+/// Loads position and equality delete files into in-memory indexes.
+
+#include <memory>
+#include <span>
+#include <string_view>
+
+#include "iceberg/iceberg_export.h"
+#include "iceberg/result.h"
+#include "iceberg/type_fwd.h"
+#include "iceberg/util/struct_like_set.h"
Review Comment:
Use forward declaration?
##########
src/iceberg/data/delete_loader.cc:
##########
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "iceberg/data/delete_loader.h"
+
+#include <string>
+#include <vector>
+
+#include "iceberg/arrow_c_data_guard_internal.h"
+#include "iceberg/deletes/position_delete_index.h"
+#include "iceberg/file_reader.h"
+#include "iceberg/manifest/manifest_entry.h"
+#include "iceberg/metadata_columns.h"
+#include "iceberg/row/arrow_array_wrapper.h"
+#include "iceberg/schema.h"
+#include "iceberg/util/macros.h"
+#include "iceberg/util/struct_like_set.h"
+
+namespace iceberg {
+
+namespace {
+
+/// \brief Build the projection schema for reading position delete files.
+std::shared_ptr<Schema> PosDeleteSchema() {
+ return std::make_shared<Schema>(std::vector<SchemaField>{
+ MetadataColumns::kDeleteFilePath,
+ MetadataColumns::kDeleteFilePos,
+ });
+}
+
+/// \brief Open a delete file with the given projection schema.
+Result<std::unique_ptr<Reader>> OpenDeleteFile(const DataFile& file,
+ std::shared_ptr<Schema> projection,
+ const std::shared_ptr<FileIO>& io) {
+ ReaderOptions options{
+ .path = file.file_path,
+ .length = static_cast<size_t>(file.file_size_in_bytes),
+ .io = io,
+ .projection = std::move(projection),
+ };
+ return ReaderFactoryRegistry::Open(file.file_format, options);
+}
+
+} // namespace
+
+DeleteLoader::DeleteLoader(std::shared_ptr<FileIO> io) : io_(std::move(io)) {}
+
+DeleteLoader::~DeleteLoader() = default;
+
+Status DeleteLoader::LoadPositionDelete(const DataFile& file, PositionDeleteIndex& index,
+ std::string_view data_file_path) const {
+ // TODO(gangwu): push down path filter to open the file.
+ ICEBERG_ASSIGN_OR_RAISE(auto reader, OpenDeleteFile(file, PosDeleteSchema(), io_));
+
+ ICEBERG_ASSIGN_OR_RAISE(auto arrow_schema, reader->Schema());
+ internal::ArrowSchemaGuard schema_guard(&arrow_schema);
+
+ while (true) {
+ ICEBERG_ASSIGN_OR_RAISE(auto batch_opt, reader->Next());
+ if (!batch_opt.has_value()) break;
+
+ auto& batch = batch_opt.value();
+ internal::ArrowArrayGuard batch_guard(&batch);
+
+ ICEBERG_ASSIGN_OR_RAISE(
+ auto row, ArrowArrayStructLike::Make(arrow_schema, batch, /*row_index=*/0));
+
+ for (int64_t i = 0; i < batch.length; ++i) {
+ if (i > 0) {
+ ICEBERG_RETURN_UNEXPECTED(row->Reset(i));
+ }
+ // Field 0: file_path
+ ICEBERG_ASSIGN_OR_RAISE(auto path_scalar, row->GetField(0));
+ auto path = std::get<std::string_view>(path_scalar);
+
+ if (path == data_file_path) {
+ // Field 1: pos
+ ICEBERG_ASSIGN_OR_RAISE(auto pos_scalar, row->GetField(1));
+ index.Delete(std::get<int64_t>(pos_scalar));
+ }
+ }
+ }
+
+ return reader->Close();
+}
+
+Status DeleteLoader::LoadDV(const DataFile& file, PositionDeleteIndex& index) const {
+ return NotSupported("Loading deletion vectors is not yet supported");
+}
+
+Result<PositionDeleteIndex> DeleteLoader::LoadPositionDeletes(
+ std::span<const std::shared_ptr<DataFile>> delete_files,
+ std::string_view data_file_path) const {
+ PositionDeleteIndex index;
+
+ for (const auto& file : delete_files) {
+ if (file->IsDeletionVector()) {
+ ICEBERG_RETURN_UNEXPECTED(LoadDV(*file, index));
+ }
Review Comment:
```suggestion
if (file->IsDeletionVector()) {
ICEBERG_RETURN_UNEXPECTED(LoadDV(*file, index));
continue;
}
```
##########
src/iceberg/data/delete_loader.cc:
##########
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#include "iceberg/data/delete_loader.h"
+
+#include <string>
+#include <vector>
+
+#include "iceberg/arrow_c_data_guard_internal.h"
+#include "iceberg/deletes/position_delete_index.h"
+#include "iceberg/file_reader.h"
+#include "iceberg/manifest/manifest_entry.h"
+#include "iceberg/metadata_columns.h"
+#include "iceberg/row/arrow_array_wrapper.h"
+#include "iceberg/schema.h"
+#include "iceberg/util/macros.h"
+#include "iceberg/util/struct_like_set.h"
+
+namespace iceberg {
+
+namespace {
+
+/// \brief Build the projection schema for reading position delete files.
+std::shared_ptr<Schema> PosDeleteSchema() {
+ return std::make_shared<Schema>(std::vector<SchemaField>{
+ MetadataColumns::kDeleteFilePath,
+ MetadataColumns::kDeleteFilePos,
+ });
+}
+
+/// \brief Open a delete file with the given projection schema.
+Result<std::unique_ptr<Reader>> OpenDeleteFile(const DataFile& file,
+ std::shared_ptr<Schema> projection,
+ const std::shared_ptr<FileIO>& io) {
+ ReaderOptions options{
+ .path = file.file_path,
+ .length = static_cast<size_t>(file.file_size_in_bytes),
+ .io = io,
+ .projection = std::move(projection),
+ };
+ return ReaderFactoryRegistry::Open(file.file_format, options);
+}
+
+} // namespace
+
+DeleteLoader::DeleteLoader(std::shared_ptr<FileIO> io) : io_(std::move(io)) {}
+
+DeleteLoader::~DeleteLoader() = default;
+
+Status DeleteLoader::LoadPositionDelete(const DataFile& file, PositionDeleteIndex& index,
+ std::string_view data_file_path) const {
+ // TODO(gangwu): push down path filter to open the file.
+ ICEBERG_ASSIGN_OR_RAISE(auto reader, OpenDeleteFile(file, PosDeleteSchema(), io_));
+
+ ICEBERG_ASSIGN_OR_RAISE(auto arrow_schema, reader->Schema());
+ internal::ArrowSchemaGuard schema_guard(&arrow_schema);
+
+ while (true) {
+ ICEBERG_ASSIGN_OR_RAISE(auto batch_opt, reader->Next());
+ if (!batch_opt.has_value()) break;
+
+ auto& batch = batch_opt.value();
+ internal::ArrowArrayGuard batch_guard(&batch);
+
+ ICEBERG_ASSIGN_OR_RAISE(
+ auto row, ArrowArrayStructLike::Make(arrow_schema, batch, /*row_index=*/0));
+
+ for (int64_t i = 0; i < batch.length; ++i) {
+ if (i > 0) {
+ ICEBERG_RETURN_UNEXPECTED(row->Reset(i));
+ }
+ // Field 0: file_path
+ ICEBERG_ASSIGN_OR_RAISE(auto path_scalar, row->GetField(0));
+ auto path = std::get<std::string_view>(path_scalar);
+
+ if (path == data_file_path) {
+ // Field 1: pos
+ ICEBERG_ASSIGN_OR_RAISE(auto pos_scalar, row->GetField(1));
+ index.Delete(std::get<int64_t>(pos_scalar));
+ }
+ }
+ }
+
+ return reader->Close();
+}
+
+Status DeleteLoader::LoadDV(const DataFile& file, PositionDeleteIndex& index) const {
+ return NotSupported("Loading deletion vectors is not yet supported");
+}
+
+Result<PositionDeleteIndex> DeleteLoader::LoadPositionDeletes(
+ std::span<const std::shared_ptr<DataFile>> delete_files,
+ std::string_view data_file_path) const {
+ PositionDeleteIndex index;
+
+ for (const auto& file : delete_files) {
Review Comment:
Can we skip opening the file directly if `DataFile::referenced_data_file` exists and is not equal to `data_file_path`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat(data): add DeleteLoader for position and equality delete files [iceberg-cpp]
Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on PR #610:
URL: https://github.com/apache/iceberg-cpp/pull/610#issuecomment-4182264252
I've addressed the comments. Thanks for the review, @zhjwpku and @gty404!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] feat(data): add DeleteLoader for position and equality delete files [iceberg-cpp]
Posted by "zhjwpku (via GitHub)" <gi...@apache.org>.
zhjwpku commented on code in PR #610:
URL: https://github.com/apache/iceberg-cpp/pull/610#discussion_r3027429748
##########
src/iceberg/data/delete_loader.h:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#pragma once
+
+/// \file iceberg/data/delete_loader.h
+/// Loads position and equality delete files into in-memory indexes.
+
+#include <memory>
+#include <span>
+#include <string_view>
+
+#include "iceberg/iceberg_export.h"
+#include "iceberg/result.h"
+#include "iceberg/type_fwd.h"
+#include "iceberg/util/struct_like_set.h"
+
+namespace iceberg {
+
+/// \brief Loads delete files and constructs in-memory delete indexes.
+class ICEBERG_EXPORT DeleteLoader {
+ public:
+ /// \brief Create a DeleteLoader.
+ /// \param io FileIO instance for reading delete files
+ explicit DeleteLoader(std::shared_ptr<FileIO> io);
+
+ ~DeleteLoader();
+
+ /// \brief Load position deletes for a specific data file.
+ ///
+ /// Reads the given position delete files and returns a PositionDeleteIndex
+ /// containing only the positions that apply to the specified data file path.
+ /// Supports both regular position delete files and deletion vectors.
+ ///
+ /// \param delete_files Position delete files to load (must have
+ /// content == Content::kPositionDeletes)
+ /// \param data_file_path Path of the data file to filter positions for
+ /// \return A PositionDeleteIndex with deleted positions for the data file
+ Result<PositionDeleteIndex> LoadPositionDeletes(
+ std::span<const std::shared_ptr<DataFile>> delete_files,
+ std::string_view data_file_path) const;
+
+ /// \brief Load equality deletes into an in-memory set.
+ ///
+ /// \param delete_files Equality delete files to load (must have
+ /// content == Content::kEqualityDeletes)
+ /// \param equality_type The struct type describing the equality columns
+ /// \return A StructLikeSet containing the deleted rows
+ Result<std::unique_ptr<UncheckedStructLikeSet>> LoadEqualityDeletes(
Review Comment:
Why LoadEqualityDeletes returns a unique ptr while LoadPositionDeletes returns a struct?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org