lxy-9602 commented on code in PR #266: URL: https://github.com/apache/paimon-cpp/pull/266#discussion_r3901009142
########## src/paimon/core/mergetree/compact/full_changelog_merge_function_wrapper_test.cpp: ########## @@ -0,0 +1,228 @@ +/* + * 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 "paimon/core/mergetree/compact/full_changelog_merge_function_wrapper.h" + +#include <memory> +#include <utility> + +#include "gtest/gtest.h" +#include "paimon/core/mergetree/compact/deduplicate_merge_function.h" +#include "paimon/core/mergetree/compact/internal_row_equalizer.h" +#include "paimon/memory/memory_pool.h" +#include "paimon/testing/utils/binary_row_generator.h" +#include "paimon/testing/utils/testharness.h" + +namespace paimon::test { +namespace { + +constexpr int32_t MAX_LEVEL = 3; + +KeyValue MakeKeyValue(const RowKind* kind, int64_t sequence_number, int32_t level, int32_t key, + int32_t value, const std::shared_ptr<MemoryPool>& pool) { + return KeyValue(kind, sequence_number, level, + BinaryRowGenerator::GenerateRowPtr({key}, pool.get()), + BinaryRowGenerator::GenerateRowPtr({value}, pool.get())); +} + +std::unique_ptr<RowCompactedSerializer> CreateValueSerializer( + const std::shared_ptr<MemoryPool>& pool) { + return RowCompactedSerializer::Create(arrow::schema({arrow::field("value", arrow::int32())}), + pool) + .value(); +} + +std::unique_ptr<FullChangelogMergeFunctionWrapper> CreateWrapper( + const std::shared_ptr<MemoryPool>& pool, + FieldsComparator::FieldComparatorFunc value_equalizer = {}) { + return std::make_unique<FullChangelogMergeFunctionWrapper>( + std::make_unique<DeduplicateMergeFunction>(/*ignore_delete=*/false), MAX_LEVEL, + CreateValueSerializer(pool), std::move(value_equalizer)); +} + +void CheckKeyValue(const KeyValue& actual, const RowKind* kind, int64_t sequence_number, + int32_t level, int32_t value) { + ASSERT_EQ(kind, actual.value_kind); + ASSERT_EQ(sequence_number, actual.sequence_number); + ASSERT_EQ(level, actual.level); + ASSERT_EQ(value, actual.value->GetInt(0)); +} + +} // namespace + +TEST(FullChangelogMergeFunctionWrapperTest, TestSingleRecord) { + auto pool = GetDefaultPool(); + auto wrapper = CreateWrapper(pool); + + wrapper->Reset(); + ASSERT_OK(wrapper->Add( + MakeKeyValue(RowKind::Insert(), /*sequence_number=*/1, /*level=*/0, 1, 10, pool))); + ASSERT_OK_AND_ASSIGN(std::optional<ChangelogResult> insert_result, wrapper->GetResult()); + ASSERT_TRUE(insert_result); + ASSERT_TRUE(insert_result->result); + ASSERT_EQ(1, insert_result->changelogs.size()); + CheckKeyValue(insert_result->changelogs[0], RowKind::Insert(), 1, KeyValue::UNKNOWN_LEVEL, 10); + CheckKeyValue(*insert_result->result, RowKind::Insert(), 1, 0, 10); + Review Comment: Please add /*sequence_number=*/, /*level=*/, /*value=*/ ########## src/paimon/core/mergetree/compact/full_changelog_merge_function_wrapper_test.cpp: ########## @@ -0,0 +1,228 @@ +/* + * 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 "paimon/core/mergetree/compact/full_changelog_merge_function_wrapper.h" + +#include <memory> +#include <utility> + +#include "gtest/gtest.h" +#include "paimon/core/mergetree/compact/deduplicate_merge_function.h" +#include "paimon/core/mergetree/compact/internal_row_equalizer.h" +#include "paimon/memory/memory_pool.h" +#include "paimon/testing/utils/binary_row_generator.h" +#include "paimon/testing/utils/testharness.h" + +namespace paimon::test { +namespace { + +constexpr int32_t MAX_LEVEL = 3; + Review Comment: kMaxLevel? ########## src/paimon/core/mergetree/compact/merge_tree_compact_manager_factory_test.cpp: ########## @@ -330,12 +330,13 @@ TEST_F(MergeTreeCompactManagerFactoryWriteTest, } TEST_F(MergeTreeCompactManagerFactoryWriteTest, - TestCreateFileStoreWriteShouldFailWhenFullCompactionChangelogConfigured) { - ASSERT_NOK_WITH_MSG(CreateSingleStringFileStoreWrite( - {{"bucket", "1"}, {Options::CHANGELOG_PRODUCER, "full-compaction"}}, - /*with_io_manager=*/false), - "C++ Paimon only supports 'none', 'input' and 'lookup' " - "changelog-producer now"); + TestWriteShouldSucceedWhenFullCompactionChangelogConfigured) { + ASSERT_OK_AND_ASSIGN(auto file_store_write, + CreateSingleStringFileStoreWrite( + {{"bucket", "1"}, {Options::CHANGELOG_PRODUCER, "full-compaction"}}, + /*with_io_manager=*/false)); + ASSERT_OK(WriteSingleStringRow(file_store_write.get(), /*bucket=*/0, "k1")); + ASSERT_OK(file_store_write->PrepareCommit(/*wait_compaction=*/true).status()); } Review Comment: `ASSERT_OK(file_store_write->PrepareCommit(/*wait_compaction=*/true))` -- 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]
