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: [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]
