Skip to content

Commit 5840cbc

Browse files
committed
refactor(core): apply ColumnarRowRef in in-memory kv reader
1 parent 50fd013 commit 5840cbc

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/paimon/core/io/key_value_in_memory_record_reader.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include "arrow/compute/ordering.h"
2828
#include "arrow/util/checked_cast.h"
2929
#include "fmt/format.h"
30-
#include "paimon/common/data/columnar/columnar_row.h"
30+
#include "paimon/common/data/columnar/columnar_row_ref.h"
3131
#include "paimon/common/data/internal_row.h"
3232
#include "paimon/common/types/row_kind.h"
3333
#include "paimon/common/utils/arrow/status_utils.h"
@@ -49,10 +49,8 @@ Result<KeyValue> KeyValueInMemoryRecordReader::Iterator::Next() {
4949
row_kind, RowKind::FromByteValue(static_cast<int8_t>(reader_->row_kinds_[index])));
5050
}
5151
// key must hold value_struct_array as min/max key may be used after projection
52-
auto key = std::make_unique<ColumnarRow>(reader_->value_struct_array_, reader_->key_fields_,
53-
reader_->pool_, index);
54-
auto value = std::make_unique<ColumnarRow>(reader_->value_struct_array_,
55-
reader_->value_fields_, reader_->pool_, index);
52+
auto key = std::make_unique<ColumnarRowRef>(reader_->key_ctx_, index);
53+
auto value = std::make_unique<ColumnarRowRef>(reader_->value_ctx_, index);
5654
KeyValue kv(row_kind, reader_->last_sequence_num_ + index,
5755
/*level=*/KeyValue::UNKNOWN_LEVEL, std::move(key), std::move(value));
5856
if (current_key == nullptr) {
@@ -104,6 +102,8 @@ Result<std::unique_ptr<KeyValueRecordReader::Iterator>> KeyValueInMemoryRecordRe
104102
for (int32_t i = 0; i < value_struct_array_->num_fields(); i++) {
105103
value_fields_.push_back(value_struct_array_->field(i));
106104
}
105+
key_ctx_ = std::make_shared<ColumnarBatchContext>(value_struct_array_, key_fields_, pool_);
106+
value_ctx_ = std::make_shared<ColumnarBatchContext>(value_struct_array_, value_fields_, pool_);
107107

108108
PAIMON_ASSIGN_OR_RAISE(sort_indices_, SortBatch());
109109
return std::make_unique<KeyValueInMemoryRecordReader::Iterator>(this);
@@ -115,6 +115,8 @@ void KeyValueInMemoryRecordReader::Close() {
115115
key_fields_.clear();
116116
value_fields_.clear();
117117
sort_indices_.reset();
118+
key_ctx_.reset();
119+
value_ctx_.reset();
118120
}
119121

120122
Result<std::shared_ptr<arrow::NumericArray<arrow::UInt64Type>>>

src/paimon/core/io/key_value_in_memory_record_reader.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Array;
3737
} // namespace arrow
3838

3939
namespace paimon {
40+
struct ColumnarBatchContext;
4041
class FieldsComparator;
4142
class MemoryPool;
4243
class Metrics;
@@ -91,5 +92,7 @@ class KeyValueInMemoryRecordReader : public KeyValueRecordReader {
9192
arrow::ArrayVector key_fields_;
9293
arrow::ArrayVector value_fields_;
9394
std::shared_ptr<arrow::NumericArray<arrow::UInt64Type>> sort_indices_;
95+
std::shared_ptr<ColumnarBatchContext> key_ctx_;
96+
std::shared_ptr<ColumnarBatchContext> value_ctx_;
9497
};
9598
} // namespace paimon

0 commit comments

Comments
 (0)