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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
