Skip to content

Commit f47c354

Browse files
committed
remove copy constructor for KeyValue
1 parent 2ef3d3a commit f47c354

File tree

5 files changed

+20
-48
lines changed

5 files changed

+20
-48
lines changed

src/paimon/common/data/generic_row.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ class GenericRow : public InternalRow {
103103
return DataDefine::IsVariantNull(fields_[pos]);
104104
}
105105

106-
void AddDataHolder(const std::shared_ptr<InternalRow>& holder) {
107-
holders_.push_back(holder);
106+
void AddDataHolder(std::unique_ptr<InternalRow>&& holder) {
107+
holders_.push_back(std::move(holder));
108108
}
109109

110110
bool GetBoolean(int32_t pos) const override {
@@ -219,7 +219,7 @@ class GenericRow : public InternalRow {
219219
std::vector<VariantType> fields_;
220220
/// As GenericRow only holds string view for string data to avoid deep copy, original data must
221221
/// be held in holders_
222-
std::vector<std::shared_ptr<InternalRow>> holders_;
222+
std::vector<std::unique_ptr<InternalRow>> holders_;
223223
/// The kind of change that a row describes in a changelog.
224224
const RowKind* kind_;
225225
};

src/paimon/core/key_value.h

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,13 @@ struct KeyValue {
3838
KeyValue() = default;
3939

4040
KeyValue(const RowKind* _value_kind, int64_t _sequence_number, int32_t _level,
41-
std::shared_ptr<InternalRow> _key, std::shared_ptr<InternalRow> _value)
41+
std::shared_ptr<InternalRow> _key, std::unique_ptr<InternalRow> _value)
4242
: value_kind(_value_kind),
4343
sequence_number(_sequence_number),
4444
level(_level),
4545
key(std::move(_key)),
4646
value(std::move(_value)) {}
4747

48-
KeyValue(const KeyValue& other) noexcept {
49-
*this = other;
50-
}
51-
52-
KeyValue& operator=(const KeyValue& other) noexcept {
53-
if (&other == this) {
54-
return *this;
55-
}
56-
value_kind = other.value_kind;
57-
sequence_number = other.sequence_number;
58-
level = other.level;
59-
key = other.key;
60-
value = other.value;
61-
return *this;
62-
}
63-
6448
KeyValue(KeyValue&& other) noexcept {
6549
*this = std::move(other);
6650
}
@@ -83,7 +67,7 @@ struct KeyValue {
8367
// determined after read from file
8468
int32_t level = -1;
8569
std::shared_ptr<InternalRow> key;
86-
std::shared_ptr<InternalRow> value;
70+
std::unique_ptr<InternalRow> value;
8771
};
8872

8973
struct KeyValueBatch {

src/paimon/core/mergetree/compact/lookup_changelog_merge_function_wrapper.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,24 +70,25 @@ class LookupChangelogMergeFunctionWrapper : public MergeFunctionWrapper<KeyValue
7070

7171
Result<std::optional<KeyValue>> GetResult() override {
7272
// 1. Find the latest high level record and compute containLevel0
73-
std::optional<KeyValue> high_level = merge_function_->PickHighLevel();
73+
std::optional<int32_t> high_level_idx = merge_function_->PickHighLevelIdx();
7474

7575
// 2. Lookup if latest high level record is absent
76-
if (high_level == std::nullopt) {
76+
if (high_level_idx == std::nullopt) {
77+
std::optional<KeyValue> lookup_high_level;
7778
PAIMON_ASSIGN_OR_RAISE(std::optional<T> lookup_result,
7879
lookup_(merge_function_->GetKey()));
7980
if (lookup_result) {
8081
std::string file_name;
8182
int64_t row_position = -1;
8283
if constexpr (std::is_same_v<T, PositionedKeyValue>) {
83-
high_level = lookup_result->key_value;
84+
lookup_high_level = std::move(lookup_result->key_value);
8485
file_name = lookup_result->file_name;
8586
row_position = lookup_result->row_position;
8687
} else if constexpr (std::is_same_v<T, FilePosition>) {
8788
file_name = lookup_result->file_name;
8889
row_position = lookup_result->row_position;
8990
} else if constexpr (std::is_same_v<T, KeyValue>) {
90-
high_level = lookup_result;
91+
lookup_high_level = std::move(lookup_result);
9192
} else {
9293
return Status::Invalid(
9394
"deletion vector mode must have PositionedKeyValue or FilePosition "
@@ -98,8 +99,8 @@ class LookupChangelogMergeFunctionWrapper : public MergeFunctionWrapper<KeyValue
9899
deletion_vectors_maintainer_->NotifyNewDeletion(file_name, row_position));
99100
}
100101
}
101-
if (high_level) {
102-
merge_function_->InsertInto(std::move(high_level), comparator_);
102+
if (lookup_high_level) {
103+
merge_function_->InsertInto(std::move(lookup_high_level), comparator_);
103104
}
104105
}
105106

src/paimon/core/mergetree/compact/lookup_merge_function.h

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,13 @@ class LookupMergeFunction : public MergeFunction {
5858
return current_key_;
5959
}
6060

61-
std::optional<KeyValue> PickHighLevel() const {
62-
int32_t idx = PickHighLevelIdx();
63-
if (idx == -1) {
64-
return std::optional<KeyValue>();
65-
}
66-
return candidates_[idx];
67-
}
68-
6961
Result<std::optional<KeyValue>> GetResult() override {
7062
merge_function_->Reset();
71-
int32_t high_level_idx = PickHighLevelIdx();
63+
std::optional<int32_t> high_level_idx = PickHighLevelIdx();
7264
for (int32_t i = 0; i < static_cast<int32_t>(candidates_.size()); ++i) {
7365
// records that has not been stored on the disk yet, such as the data in the write
7466
// buffer being at level -1
75-
if (candidates_[i].level <= 0 || i == high_level_idx) {
67+
if (candidates_[i].level <= 0 || i == high_level_idx.value()) {
7668
PAIMON_RETURN_NOT_OK(merge_function_->Add(std::move(candidates_[i])));
7769
}
7870
}
@@ -88,9 +80,8 @@ class LookupMergeFunction : public MergeFunction {
8880
std::sort(candidates_.begin(), candidates_.end(), cmp_function);
8981
}
9082

91-
private:
92-
int32_t PickHighLevelIdx() const {
93-
int32_t high_level_idx = -1;
83+
std::optional<int32_t> PickHighLevelIdx() const {
84+
std::optional<int32_t> high_level_idx;
9485
for (int32_t i = 0; i < static_cast<int32_t>(candidates_.size()); i++) {
9586
const auto& kv = candidates_[i];
9687
// records that has not been stored on the disk yet, such as the data in the write
@@ -100,7 +91,7 @@ class LookupMergeFunction : public MergeFunction {
10091
}
10192
// For high-level comparison logic (not involving Level 0), only the value of the
10293
// minimum Level should be selected
103-
if (high_level_idx == -1 || kv.level < candidates_[high_level_idx].level) {
94+
if (!high_level_idx || kv.level < candidates_[high_level_idx.value()].level) {
10495
high_level_idx = i;
10596
}
10697
}

src/paimon/core/mergetree/compact/lookup_merge_function_test.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ TEST(LookupMergeFunctionTest, TestPickHighLevel) {
127127
auto pool = GetDefaultPool();
128128

129129
merge_func->Reset();
130-
ASSERT_FALSE(merge_func->PickHighLevel());
130+
ASSERT_FALSE(merge_func->PickHighLevelIdx());
131131
ASSERT_FALSE(merge_func->ContainLevel0());
132132

133133
merge_func->Reset();
@@ -145,12 +145,8 @@ TEST(LookupMergeFunctionTest, TestPickHighLevel) {
145145
ASSERT_OK(merge_func->Add(std::move(kv2)));
146146
ASSERT_OK(merge_func->Add(std::move(kv3)));
147147
ASSERT_TRUE(merge_func->ContainLevel0());
148-
ASSERT_EQ(merge_func->GetKey()->GetInt(0), 10);
149-
auto result_kv = std::move(merge_func->PickHighLevel().value());
150-
KeyValue expected(RowKind::Insert(), /*sequence_number=*/2, /*level=*/1, /*key=*/
151-
BinaryRowGenerator::GenerateRowPtr({10}, pool.get()),
152-
/*value=*/BinaryRowGenerator::GenerateRowPtr({10, 200}, pool.get()));
153-
KeyValueChecker::CheckResult(expected, result_kv, /*key_arity=*/1, /*value_arity=*/2);
148+
ASSERT_EQ(merge_func->GetKey()->GetInt(0), 10);
149+
ASSERT_EQ(merge_func->PickHighLevelIdx(), 1);
154150
}
155151

156152
TEST(LookupMergeFunctionTest, TestInsertInto) {

0 commit comments

Comments
 (0)