You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "manuzhang (via GitHub)" <gi...@apache.org> on 2026/06/10 15:04:42 UTC
[PR] feat: add row delta update [iceberg-cpp]
manuzhang opened a new pull request, #721:
URL: https://github.com/apache/iceberg-cpp/pull/721
Implements the RowDelta update builder, table and transaction factory methods, and focused tests for row-level add/delete flows.
--
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: add row delta update [iceberg-cpp]
Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #721:
URL: https://github.com/apache/iceberg-cpp/pull/721#discussion_r3453512800
##########
src/iceberg/update/row_delta.cc:
##########
@@ -0,0 +1,191 @@
+/*
+ * 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/update/row_delta.h"
+
+#include <memory>
+#include <string>
+#include <string_view>
+#include <utility>
+#include <vector>
+
+#include "iceberg/expression/expressions.h"
+#include "iceberg/manifest/manifest_entry.h"
+#include "iceberg/snapshot.h"
+#include "iceberg/table.h"
+#include "iceberg/table_metadata.h"
+#include "iceberg/transaction.h"
+#include "iceberg/util/error_collector.h"
+#include "iceberg/util/formatter_internal.h"
+#include "iceberg/util/macros.h"
+#include "iceberg/util/snapshot_util_internal.h"
+
+namespace iceberg {
+
+Result<std::unique_ptr<RowDelta>> RowDelta::Make(
+ std::string table_name, std::shared_ptr<TransactionContext> ctx) {
+ ICEBERG_PRECHECK(!table_name.empty(), "Table name cannot be empty");
+ ICEBERG_PRECHECK(ctx != nullptr, "Cannot create RowDelta without a context");
+ return std::unique_ptr<RowDelta>(new RowDelta(std::move(table_name), std::move(ctx)));
+}
+
+RowDelta::RowDelta(std::string table_name, std::shared_ptr<TransactionContext> ctx)
+ : MergingSnapshotUpdate(std::move(table_name), std::move(ctx)),
+ conflict_detection_filter_(Expressions::AlwaysTrue()) {}
+
+RowDelta& RowDelta::AddRows(const std::shared_ptr<DataFile>& inserts) {
+ ICEBERG_BUILDER_RETURN_IF_ERROR(AddDataFile(inserts));
+ return *this;
+}
+
+RowDelta& RowDelta::AddDeletes(const std::shared_ptr<DataFile>& deletes) {
+ ICEBERG_BUILDER_RETURN_IF_ERROR(AddDeleteFile(deletes));
+ return *this;
+}
+
+RowDelta& RowDelta::RemoveRows(const std::shared_ptr<DataFile>& file) {
+ ICEBERG_BUILDER_RETURN_IF_ERROR(DeleteDataFile(file));
+ removed_data_files_.insert(file);
+ return *this;
+}
+
+RowDelta& RowDelta::RemoveDeletes(const std::shared_ptr<DataFile>& deletes) {
+ ICEBERG_BUILDER_RETURN_IF_ERROR(DeleteDeleteFile(deletes));
+ return *this;
+}
+
+RowDelta& RowDelta::ValidateFromSnapshot(int64_t snapshot_id) {
+ starting_snapshot_id_ = snapshot_id;
+ return *this;
+}
+
+RowDelta& RowDelta::CaseSensitive(bool case_sensitive) {
+ MergingSnapshotUpdate::CaseSensitive(case_sensitive);
+ return *this;
+}
+
+RowDelta& RowDelta::ValidateDataFilesExist(
+ std::span<const std::string> referenced_files) {
+ for (const auto& file : referenced_files) {
+ referenced_data_files_.insert(file);
+ }
+ return *this;
+}
+
+RowDelta& RowDelta::ValidateDeletedFiles() {
+ validate_deletes_ = true;
+ return *this;
+}
+
+RowDelta& RowDelta::ConflictDetectionFilter(std::shared_ptr<Expression> filter) {
+ ICEBERG_BUILDER_CHECK(filter != nullptr, "Conflict detection filter cannot be null");
+ conflict_detection_filter_ = std::move(filter);
+ return *this;
+}
+
+RowDelta& RowDelta::ValidateNoConflictingDataFiles() {
+ validate_new_data_files_ = true;
+ return *this;
+}
+
+RowDelta& RowDelta::ValidateNoConflictingDeleteFiles() {
+ validate_new_delete_files_ = true;
+ return *this;
+}
+
+std::string RowDelta::operation() {
+ if (AddsDataFiles() && !AddsDeleteFiles() && !DeletesDataFiles() &&
+ !DeletesDeleteFiles()) {
Review Comment:
Java's BaseRowDelta still returns APPEND when rows are added and only delete files are removed. This extra check makes AddRows + RemoveDeletes produce OVERWRITE, which breaks parity.
##########
src/iceberg/table.cc:
##########
@@ -231,6 +232,12 @@ Result<std::shared_ptr<DeleteFiles>> Table::NewDeleteFiles() {
return DeleteFiles::Make(name().name, std::move(ctx));
}
+Result<std::shared_ptr<RowDelta>> Table::NewRowDelta() {
Review Comment:
StaticTable should override this and return NotSupported, like the other update factories. Otherwise a read-only table can create a RowDelta builder.
--
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: add row delta update [iceberg-cpp]
Posted by "manuzhang (via GitHub)" <gi...@apache.org>.
manuzhang commented on code in PR #721:
URL: https://github.com/apache/iceberg-cpp/pull/721#discussion_r3426504932
##########
src/iceberg/update/merging_snapshot_update.h:
##########
@@ -288,6 +288,14 @@ class ICEBERG_EXPORT MergingSnapshotUpdate : public SnapshotUpdate {
const std::shared_ptr<Snapshot>& parent, std::shared_ptr<FileIO> io,
bool case_sensitive = true);
+ /// \brief Return an error if a staged deletion vector conflicts with a deletion
+ /// vector added since starting_snapshot_id.
+ Status ValidateAddedDVs(const TableMetadata& metadata,
Review Comment:
It's already protected.
--
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: add row delta update [iceberg-cpp]
Posted by "WZhuo (via GitHub)" <gi...@apache.org>.
WZhuo commented on PR #721:
URL: https://github.com/apache/iceberg-cpp/pull/721#issuecomment-4737271346
One suggestion: in `RowDelta::ValidateNoConfirmedFileAndPositionDeletes()`, the `conflicting_files` vector could use `std::vector<std::string_view>` instead of `std::vector<std::string>` to avoid unnecessary string copies.
```cpp
std::vector<std::string_view> conflicting_files;
```
This is safe because:
- `file->file_path` is a `std::string` member of `DataFile`
- `removed_data_files_` holds `shared_ptr<DataFile>`, so the backing strings live through the function
- `conflicting_files` is a local only consumed by `FormatRange` before returning — the `string_view`s never escape the scope
--
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: add row delta update [iceberg-cpp]
Posted by "WZhuo (via GitHub)" <gi...@apache.org>.
WZhuo commented on code in PR #721:
URL: https://github.com/apache/iceberg-cpp/pull/721#discussion_r3420518839
##########
src/iceberg/test/row_delta_test.cc:
##########
@@ -0,0 +1,287 @@
+/*
+ * 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/update/row_delta.h"
+
+#include <memory>
+#include <optional>
+#include <string>
+#include <vector>
+
+#include <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+#include "iceberg/avro/avro_register.h"
+#include "iceberg/manifest/manifest_entry.h"
+#include "iceberg/partition_spec.h"
+#include "iceberg/row/partition_values.h"
+#include "iceberg/schema.h"
+#include "iceberg/snapshot.h"
+#include "iceberg/table.h"
+#include "iceberg/table_metadata.h"
+#include "iceberg/test/matchers.h"
+#include "iceberg/test/update_test_base.h"
+#include "iceberg/update/fast_append.h"
+
+namespace iceberg {
+
+class RowDeltaTest : public MinimalUpdateTestBase {
Review Comment:
It could be better add some tests that commit a conflicting data/delete file after the starting snapshot and assert ValidationFailed from each validator.
##########
src/iceberg/update/merging_snapshot_update.h:
##########
@@ -288,6 +288,14 @@ class ICEBERG_EXPORT MergingSnapshotUpdate : public SnapshotUpdate {
const std::shared_ptr<Snapshot>& parent, std::shared_ptr<FileIO> io,
bool case_sensitive = true);
+ /// \brief Return an error if a staged deletion vector conflicts with a deletion
+ /// vector added since starting_snapshot_id.
+ Status ValidateAddedDVs(const TableMetadata& metadata,
Review Comment:
`protected` is sufficient and keeps this internal validation helper from leaking into the public surface of every merge-based update.
##########
src/iceberg/update/row_delta.cc:
##########
@@ -0,0 +1,196 @@
+/*
+ * 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/update/row_delta.h"
+
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "iceberg/expression/expressions.h"
+#include "iceberg/manifest/manifest_entry.h"
+#include "iceberg/snapshot.h"
+#include "iceberg/table.h"
+#include "iceberg/table_metadata.h"
+#include "iceberg/transaction.h"
+#include "iceberg/util/error_collector.h"
+#include "iceberg/util/macros.h"
+#include "iceberg/util/snapshot_util_internal.h"
+
+namespace iceberg {
+
+Result<std::unique_ptr<RowDelta>> RowDelta::Make(
+ std::string table_name, std::shared_ptr<TransactionContext> ctx) {
+ ICEBERG_PRECHECK(!table_name.empty(), "Table name cannot be empty");
+ ICEBERG_PRECHECK(ctx != nullptr, "Cannot create RowDelta without a context");
+ return std::unique_ptr<RowDelta>(new RowDelta(std::move(table_name), std::move(ctx)));
+}
+
+RowDelta::RowDelta(std::string table_name, std::shared_ptr<TransactionContext> ctx)
+ : MergingSnapshotUpdate(std::move(table_name), std::move(ctx)),
+ conflict_detection_filter_(Expressions::AlwaysTrue()) {}
+
+RowDelta& RowDelta::AddRows(const std::shared_ptr<DataFile>& inserts) {
+ ICEBERG_BUILDER_RETURN_IF_ERROR(AddDataFile(inserts));
+ return *this;
+}
+
+RowDelta& RowDelta::AddDeletes(const std::shared_ptr<DataFile>& deletes) {
+ ICEBERG_BUILDER_RETURN_IF_ERROR(AddDeleteFile(deletes));
+ return *this;
+}
+
+RowDelta& RowDelta::RemoveRows(const std::shared_ptr<DataFile>& file) {
+ ICEBERG_BUILDER_CHECK(file != nullptr, "Cannot remove a null data file");
+ removed_data_files_.insert(file);
+ ICEBERG_BUILDER_RETURN_IF_ERROR(DeleteDataFile(file));
Review Comment:
```suggestion
ICEBERG_BUILDER_RETURN_IF_ERROR(DeleteDataFile(file));
removed_data_files_.insert(file);
```
--
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: add row delta update [iceberg-cpp]
Posted by "WZhuo (via GitHub)" <gi...@apache.org>.
WZhuo commented on code in PR #721:
URL: https://github.com/apache/iceberg-cpp/pull/721#discussion_r3432622703
##########
src/iceberg/update/row_delta.cc:
##########
@@ -0,0 +1,189 @@
+/*
+ * 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/update/row_delta.h"
+
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "iceberg/expression/expressions.h"
+#include "iceberg/manifest/manifest_entry.h"
+#include "iceberg/snapshot.h"
+#include "iceberg/table.h"
+#include "iceberg/table_metadata.h"
+#include "iceberg/transaction.h"
+#include "iceberg/util/error_collector.h"
+#include "iceberg/util/formatter_internal.h"
+#include "iceberg/util/macros.h"
+#include "iceberg/util/snapshot_util_internal.h"
+
+namespace iceberg {
+
+Result<std::unique_ptr<RowDelta>> RowDelta::Make(
+ std::string table_name, std::shared_ptr<TransactionContext> ctx) {
+ ICEBERG_PRECHECK(!table_name.empty(), "Table name cannot be empty");
+ ICEBERG_PRECHECK(ctx != nullptr, "Cannot create RowDelta without a context");
+ return std::unique_ptr<RowDelta>(new RowDelta(std::move(table_name), std::move(ctx)));
+}
+
+RowDelta::RowDelta(std::string table_name, std::shared_ptr<TransactionContext> ctx)
+ : MergingSnapshotUpdate(std::move(table_name), std::move(ctx)),
+ conflict_detection_filter_(Expressions::AlwaysTrue()) {}
+
+RowDelta& RowDelta::AddRows(const std::shared_ptr<DataFile>& inserts) {
+ ICEBERG_BUILDER_RETURN_IF_ERROR(AddDataFile(inserts));
+ return *this;
+}
+
+RowDelta& RowDelta::AddDeletes(const std::shared_ptr<DataFile>& deletes) {
+ ICEBERG_BUILDER_RETURN_IF_ERROR(AddDeleteFile(deletes));
+ return *this;
+}
+
+RowDelta& RowDelta::RemoveRows(const std::shared_ptr<DataFile>& file) {
+ ICEBERG_BUILDER_RETURN_IF_ERROR(DeleteDataFile(file));
+ removed_data_files_.insert(file);
+ return *this;
+}
+
+RowDelta& RowDelta::RemoveDeletes(const std::shared_ptr<DataFile>& deletes) {
+ ICEBERG_BUILDER_RETURN_IF_ERROR(DeleteDeleteFile(deletes));
+ return *this;
+}
+
+RowDelta& RowDelta::ValidateFromSnapshot(int64_t snapshot_id) {
+ starting_snapshot_id_ = snapshot_id;
+ return *this;
+}
+
+RowDelta& RowDelta::CaseSensitive(bool case_sensitive) {
+ MergingSnapshotUpdate::CaseSensitive(case_sensitive);
+ return *this;
+}
+
+RowDelta& RowDelta::ValidateDataFilesExist(
+ std::span<const std::string> referenced_files) {
+ for (const auto& file : referenced_files) {
+ referenced_data_files_.insert(file);
+ }
+ return *this;
+}
+
+RowDelta& RowDelta::ValidateDeletedFiles() {
+ validate_deletes_ = true;
+ return *this;
+}
+
+RowDelta& RowDelta::ConflictDetectionFilter(std::shared_ptr<Expression> filter) {
+ ICEBERG_BUILDER_CHECK(filter != nullptr, "Conflict detection filter cannot be null");
+ conflict_detection_filter_ = std::move(filter);
+ return *this;
+}
+
+RowDelta& RowDelta::ValidateNoConflictingDataFiles() {
+ validate_new_data_files_ = true;
+ return *this;
+}
+
+RowDelta& RowDelta::ValidateNoConflictingDeleteFiles() {
+ validate_new_delete_files_ = true;
+ return *this;
+}
+
+std::string RowDelta::operation() {
+ if (AddsDataFiles() && !AddsDeleteFiles() && !DeletesDataFiles()) {
+ return DataOperation::kAppend;
+ }
+
+ if (AddsDeleteFiles() && !AddsDataFiles()) {
+ return DataOperation::kDelete;
+ }
+
+ return DataOperation::kOverwrite;
+}
+
+Status RowDelta::Validate(const TableMetadata& current_metadata,
+ const std::shared_ptr<Snapshot>& snapshot) {
+ if (snapshot == nullptr) {
+ return {};
+ }
+
+ if (validate_deletes_) {
+ FailMissingDeletePaths();
+ }
+
+ if (starting_snapshot_id_.has_value()) {
+ ICEBERG_ASSIGN_OR_RAISE(bool is_ancestor, SnapshotUtil::IsAncestorOf(
+ current_metadata, snapshot->snapshot_id,
+ starting_snapshot_id_.value()));
+ ICEBERG_CHECK(is_ancestor, "Snapshot {} is not an ancestor of {}",
+ starting_snapshot_id_.value(), snapshot->snapshot_id);
+ }
+
+ auto io = ctx_->table->io();
+ if (!referenced_data_files_.empty()) {
+ ICEBERG_RETURN_UNEXPECTED(MergingSnapshotUpdate::ValidateDataFilesExist(
+ current_metadata, starting_snapshot_id_, referenced_data_files_,
+ !validate_deletes_, conflict_detection_filter_, snapshot, io, IsCaseSensitive()));
+ }
+
+ if (validate_new_data_files_) {
+ ICEBERG_RETURN_UNEXPECTED(MergingSnapshotUpdate::ValidateAddedDataFiles(
+ current_metadata, starting_snapshot_id_, conflict_detection_filter_, snapshot, io,
+ IsCaseSensitive()));
+ }
+
+ if (validate_new_delete_files_) {
+ if (!removed_data_files_.empty()) {
+ ICEBERG_RETURN_UNEXPECTED(MergingSnapshotUpdate::ValidateNoNewDeletesForDataFiles(
+ current_metadata, starting_snapshot_id_, conflict_detection_filter_,
+ removed_data_files_, snapshot, io, IsCaseSensitive()));
+ }
+
+ ICEBERG_RETURN_UNEXPECTED(MergingSnapshotUpdate::ValidateNoNewDeleteFiles(
+ current_metadata, starting_snapshot_id_, conflict_detection_filter_, snapshot, io,
+ IsCaseSensitive()));
+ }
+
+ ICEBERG_RETURN_UNEXPECTED(ValidateNoConflictingFileAndPositionDeletes());
+
+ return MergingSnapshotUpdate::ValidateAddedDVs(
+ current_metadata, starting_snapshot_id_, conflict_detection_filter_, snapshot, io);
+}
+
+Status RowDelta::ValidateNoConflictingFileAndPositionDeletes() const {
+ std::vector<std::string> conflicting_files;
+ for (const auto& file : removed_data_files_) {
Review Comment:
Suggestion: `conflicting_files` could use `std::vector<std::string_view>` instead of `std::vector<std::string>` to avoid unnecessary string copies.
This is safe because:
- `file->file_path` is a `std::string` member of `DataFile`
- `removed_data_files_` holds `shared_ptr<DataFile>`, so the backing strings live through the function
- `conflicting_files` is a local only consumed by `FormatRange` before returning — the `string_view`s never escape the scope
--
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: add row delta update [iceberg-cpp]
Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac merged PR #721:
URL: https://github.com/apache/iceberg-cpp/pull/721
--
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: add row delta update [iceberg-cpp]
Posted by "WZhuo (via GitHub)" <gi...@apache.org>.
WZhuo commented on code in PR #721:
URL: https://github.com/apache/iceberg-cpp/pull/721#discussion_r3420548128
##########
src/iceberg/update/row_delta.cc:
##########
@@ -0,0 +1,196 @@
+/*
+ * 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/update/row_delta.h"
+
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "iceberg/expression/expressions.h"
+#include "iceberg/manifest/manifest_entry.h"
+#include "iceberg/snapshot.h"
+#include "iceberg/table.h"
+#include "iceberg/table_metadata.h"
+#include "iceberg/transaction.h"
+#include "iceberg/util/error_collector.h"
+#include "iceberg/util/macros.h"
+#include "iceberg/util/snapshot_util_internal.h"
+
+namespace iceberg {
+
+Result<std::unique_ptr<RowDelta>> RowDelta::Make(
+ std::string table_name, std::shared_ptr<TransactionContext> ctx) {
+ ICEBERG_PRECHECK(!table_name.empty(), "Table name cannot be empty");
+ ICEBERG_PRECHECK(ctx != nullptr, "Cannot create RowDelta without a context");
+ return std::unique_ptr<RowDelta>(new RowDelta(std::move(table_name), std::move(ctx)));
+}
+
+RowDelta::RowDelta(std::string table_name, std::shared_ptr<TransactionContext> ctx)
+ : MergingSnapshotUpdate(std::move(table_name), std::move(ctx)),
+ conflict_detection_filter_(Expressions::AlwaysTrue()) {}
+
+RowDelta& RowDelta::AddRows(const std::shared_ptr<DataFile>& inserts) {
+ ICEBERG_BUILDER_RETURN_IF_ERROR(AddDataFile(inserts));
+ return *this;
+}
+
+RowDelta& RowDelta::AddDeletes(const std::shared_ptr<DataFile>& deletes) {
+ ICEBERG_BUILDER_RETURN_IF_ERROR(AddDeleteFile(deletes));
+ return *this;
+}
+
+RowDelta& RowDelta::RemoveRows(const std::shared_ptr<DataFile>& file) {
+ ICEBERG_BUILDER_CHECK(file != nullptr, "Cannot remove a null data file");
+ removed_data_files_.insert(file);
+ ICEBERG_BUILDER_RETURN_IF_ERROR(DeleteDataFile(file));
+ return *this;
+}
+
+RowDelta& RowDelta::RemoveDeletes(const std::shared_ptr<DataFile>& deletes) {
+ ICEBERG_BUILDER_RETURN_IF_ERROR(DeleteDeleteFile(deletes));
+ return *this;
+}
+
+RowDelta& RowDelta::ValidateFromSnapshot(int64_t snapshot_id) {
+ starting_snapshot_id_ = snapshot_id;
+ return *this;
+}
+
+RowDelta& RowDelta::CaseSensitive(bool case_sensitive) {
+ MergingSnapshotUpdate::CaseSensitive(case_sensitive);
+ return *this;
+}
+
+RowDelta& RowDelta::ValidateDataFilesExist(
+ std::span<const std::string> referenced_files) {
+ for (const auto& file : referenced_files) {
+ referenced_data_files_.insert(file);
+ }
+ return *this;
+}
+
+RowDelta& RowDelta::ValidateDeletedFiles() {
+ validate_deletes_ = true;
+ return *this;
+}
+
+RowDelta& RowDelta::ConflictDetectionFilter(std::shared_ptr<Expression> filter) {
+ ICEBERG_BUILDER_CHECK(filter != nullptr, "Conflict detection filter cannot be null");
+ conflict_detection_filter_ = std::move(filter);
+ return *this;
+}
+
+RowDelta& RowDelta::ValidateNoConflictingDataFiles() {
+ validate_new_data_files_ = true;
+ return *this;
+}
+
+RowDelta& RowDelta::ValidateNoConflictingDeleteFiles() {
+ validate_new_delete_files_ = true;
+ return *this;
+}
+
+std::string RowDelta::operation() {
+ if (AddsDataFiles() && !AddsDeleteFiles() && !DeletesDataFiles()) {
+ return DataOperation::kAppend;
+ }
+
+ if (AddsDeleteFiles() && !AddsDataFiles()) {
+ return DataOperation::kDelete;
+ }
+
+ return DataOperation::kOverwrite;
+}
+
+Status RowDelta::Validate(const TableMetadata& current_metadata,
+ const std::shared_ptr<Snapshot>& snapshot) {
+ if (snapshot == nullptr) {
+ return {};
+ }
+
+ if (validate_deletes_) {
+ FailMissingDeletePaths();
+ }
+
+ if (starting_snapshot_id_.has_value()) {
+ ICEBERG_ASSIGN_OR_RAISE(bool is_ancestor, SnapshotUtil::IsAncestorOf(
+ current_metadata, snapshot->snapshot_id,
+ starting_snapshot_id_.value()));
+ ICEBERG_CHECK(is_ancestor, "Snapshot {} is not an ancestor of {}",
+ starting_snapshot_id_.value(), snapshot->snapshot_id);
+ }
+
+ auto io = ctx_->table->io();
+ if (!referenced_data_files_.empty()) {
+ ICEBERG_RETURN_UNEXPECTED(MergingSnapshotUpdate::ValidateDataFilesExist(
+ current_metadata, starting_snapshot_id_, referenced_data_files_,
+ !validate_deletes_, conflict_detection_filter_, snapshot, io, IsCaseSensitive()));
+ }
+
+ if (validate_new_data_files_) {
+ ICEBERG_RETURN_UNEXPECTED(MergingSnapshotUpdate::ValidateAddedDataFiles(
+ current_metadata, starting_snapshot_id_, conflict_detection_filter_, snapshot, io,
+ IsCaseSensitive()));
+ }
+
+ if (validate_new_delete_files_) {
+ if (!removed_data_files_.empty()) {
+ ICEBERG_RETURN_UNEXPECTED(MergingSnapshotUpdate::ValidateNoNewDeletesForDataFiles(
+ current_metadata, starting_snapshot_id_, conflict_detection_filter_,
+ removed_data_files_, snapshot, io, IsCaseSensitive()));
+ }
+
+ ICEBERG_RETURN_UNEXPECTED(MergingSnapshotUpdate::ValidateNoNewDeleteFiles(
+ current_metadata, starting_snapshot_id_, conflict_detection_filter_, snapshot, io,
+ IsCaseSensitive()));
+ }
+
+ ICEBERG_RETURN_UNEXPECTED(ValidateNoConflictingFileAndPositionDeletes());
+
+ return MergingSnapshotUpdate::ValidateAddedDVs(
+ current_metadata, starting_snapshot_id_, conflict_detection_filter_, snapshot, io);
+}
+
+Status RowDelta::ValidateNoConflictingFileAndPositionDeletes() const {
+ std::vector<std::string> conflicting_files;
+ for (const auto& file : removed_data_files_) {
+ if (file != nullptr && referenced_data_files_.contains(file->file_path)) {
+ conflicting_files.push_back(file->file_path);
+ }
+ }
+
+ if (!conflicting_files.empty()) {
+ std::string files = "[";
+ for (size_t i = 0; i < conflicting_files.size(); ++i) {
+ if (i > 0) {
+ files += ", ";
+ }
+ files += conflicting_files[i];
+ }
+ files += "]";
+ return ValidationFailed(
+ "Cannot delete data files {} that are referenced by new delete files", files);
+ }
Review Comment:
`FormatRange` defined in iceberg/util/formatter_internal.h could be used.
--
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: add row delta update [iceberg-cpp]
Posted by "wgtmac (via GitHub)" <gi...@apache.org>.
wgtmac commented on code in PR #721:
URL: https://github.com/apache/iceberg-cpp/pull/721#discussion_r3458187061
##########
src/iceberg/update/row_delta.cc:
##########
@@ -0,0 +1,191 @@
+/*
+ * 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/update/row_delta.h"
+
+#include <memory>
+#include <string>
+#include <string_view>
+#include <utility>
+#include <vector>
+
+#include "iceberg/expression/expressions.h"
+#include "iceberg/manifest/manifest_entry.h"
+#include "iceberg/snapshot.h"
+#include "iceberg/table.h"
+#include "iceberg/table_metadata.h"
+#include "iceberg/transaction.h"
+#include "iceberg/util/error_collector.h"
+#include "iceberg/util/formatter_internal.h"
+#include "iceberg/util/macros.h"
+#include "iceberg/util/snapshot_util_internal.h"
+
+namespace iceberg {
+
+Result<std::unique_ptr<RowDelta>> RowDelta::Make(
+ std::string table_name, std::shared_ptr<TransactionContext> ctx) {
+ ICEBERG_PRECHECK(!table_name.empty(), "Table name cannot be empty");
+ ICEBERG_PRECHECK(ctx != nullptr, "Cannot create RowDelta without a context");
+ return std::unique_ptr<RowDelta>(new RowDelta(std::move(table_name), std::move(ctx)));
+}
+
+RowDelta::RowDelta(std::string table_name, std::shared_ptr<TransactionContext> ctx)
+ : MergingSnapshotUpdate(std::move(table_name), std::move(ctx)),
+ conflict_detection_filter_(Expressions::AlwaysTrue()) {}
+
+RowDelta& RowDelta::AddRows(const std::shared_ptr<DataFile>& inserts) {
+ ICEBERG_BUILDER_RETURN_IF_ERROR(AddDataFile(inserts));
+ return *this;
+}
+
+RowDelta& RowDelta::AddDeletes(const std::shared_ptr<DataFile>& deletes) {
+ ICEBERG_BUILDER_RETURN_IF_ERROR(AddDeleteFile(deletes));
+ return *this;
+}
+
+RowDelta& RowDelta::RemoveRows(const std::shared_ptr<DataFile>& file) {
+ ICEBERG_BUILDER_RETURN_IF_ERROR(DeleteDataFile(file));
+ removed_data_files_.insert(file);
+ return *this;
+}
+
+RowDelta& RowDelta::RemoveDeletes(const std::shared_ptr<DataFile>& deletes) {
+ ICEBERG_BUILDER_RETURN_IF_ERROR(DeleteDeleteFile(deletes));
+ return *this;
+}
+
+RowDelta& RowDelta::ValidateFromSnapshot(int64_t snapshot_id) {
+ starting_snapshot_id_ = snapshot_id;
+ return *this;
+}
+
+RowDelta& RowDelta::CaseSensitive(bool case_sensitive) {
+ MergingSnapshotUpdate::CaseSensitive(case_sensitive);
+ return *this;
+}
+
+RowDelta& RowDelta::ValidateDataFilesExist(
+ std::span<const std::string> referenced_files) {
+ for (const auto& file : referenced_files) {
+ referenced_data_files_.insert(file);
+ }
+ return *this;
+}
+
+RowDelta& RowDelta::ValidateDeletedFiles() {
+ validate_deletes_ = true;
+ return *this;
+}
+
+RowDelta& RowDelta::ConflictDetectionFilter(std::shared_ptr<Expression> filter) {
+ ICEBERG_BUILDER_CHECK(filter != nullptr, "Conflict detection filter cannot be null");
+ conflict_detection_filter_ = std::move(filter);
+ return *this;
+}
+
+RowDelta& RowDelta::ValidateNoConflictingDataFiles() {
+ validate_new_data_files_ = true;
+ return *this;
+}
+
+RowDelta& RowDelta::ValidateNoConflictingDeleteFiles() {
+ validate_new_delete_files_ = true;
+ return *this;
+}
+
+std::string RowDelta::operation() {
+ if (AddsDataFiles() && !AddsDeleteFiles() && !DeletesDataFiles()) {
+ return DataOperation::kAppend;
+ }
+
+ if (AddsDeleteFiles() && !AddsDataFiles()) {
+ return DataOperation::kDelete;
+ }
+
+ return DataOperation::kOverwrite;
+}
+
+Status RowDelta::Validate(const TableMetadata& current_metadata,
+ const std::shared_ptr<Snapshot>& snapshot) {
+ if (snapshot == nullptr) {
+ return {};
+ }
+
+ if (validate_deletes_) {
+ FailMissingDeletePaths();
+ }
+
+ if (starting_snapshot_id_.has_value()) {
+ ICEBERG_ASSIGN_OR_RAISE(bool is_ancestor, SnapshotUtil::IsAncestorOf(
+ current_metadata, snapshot->snapshot_id,
+ starting_snapshot_id_.value()));
+ ICEBERG_CHECK(is_ancestor, "Snapshot {} is not an ancestor of {}",
+ starting_snapshot_id_.value(), snapshot->snapshot_id);
+ }
+
+ auto io = ctx_->table->io();
+ if (!referenced_data_files_.empty()) {
+ ICEBERG_RETURN_UNEXPECTED(MergingSnapshotUpdate::ValidateDataFilesExist(
+ current_metadata, starting_snapshot_id_, referenced_data_files_,
+ /*skip_deletes=*/false, conflict_detection_filter_, snapshot, io,
Review Comment:
This should stay tied to validate_deletes_. Java only checks DELETE snapshots here after validateDeletedFiles() is enabled; otherwise validateDataFilesExist skips concurrent deletes.
--
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