fix: Fix the reference to a variable after it has been moved (#35875) (#35904)

pr: #35875

Signed-off-by: luzhang <luzhang@zilliz.com>
Co-authored-by: luzhang <luzhang@zilliz.com>
This commit is contained in:
zhagnlu 2024-09-03 11:49:03 +08:00 committed by GitHub
parent df8d1c7ca3
commit 55df25387e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 116 additions and 4 deletions

View File

@ -98,6 +98,118 @@ class FieldDataBase {
const DataType data_type_;
};
template <typename Type>
class FieldBitsetImpl : public FieldDataBase {
public:
FieldBitsetImpl() = delete;
FieldBitsetImpl(FieldBitsetImpl&&) = delete;
FieldBitsetImpl(const FieldBitsetImpl&) = delete;
FieldBitsetImpl&
operator=(FieldBitsetImpl&&) = delete;
FieldBitsetImpl&
operator=(const FieldBitsetImpl&) = delete;
explicit FieldBitsetImpl(DataType data_type, TargetBitmap&& bitmap)
: FieldDataBase(data_type), length_(bitmap.size()) {
data_ = std::move(bitmap).into();
cap_ = data_.size() * sizeof(Type) * 8;
Assert(cap_ >= length_);
}
// FillFieldData used for read and write with storage,
// no need to implement for bitset which used in runtime process.
void
FillFieldData(const void* source, ssize_t element_count) override {
PanicInfo(NotImplemented,
"FillFieldData(const void* source, ssize_t element_count)"
"not implemented for bitset");
}
void
FillFieldData(const std::shared_ptr<arrow::Array> array) override {
PanicInfo(NotImplemented,
"FillFieldData(const std::shared_ptr<arrow::Array>& array) "
"not implemented for bitset");
}
void*
Data() override {
return data_.data();
}
const void*
RawValue(ssize_t offset) const override {
PanicInfo(NotImplemented,
"RawValue(ssize_t offset) not implemented for bitset");
}
int64_t
Size() const override {
return sizeof(Type) * get_num_rows();
}
int64_t
Size(ssize_t offset) const override {
AssertInfo(offset < get_num_rows(),
"field data subscript out of range");
AssertInfo(offset < get_length(),
"subscript position don't has valid value");
return sizeof(Type);
}
size_t
Length() const override {
return get_length();
}
bool
IsFull() const override {
auto cap_num_rows = get_num_rows();
auto filled_num_rows = get_length();
return cap_num_rows == filled_num_rows;
}
void
Reserve(size_t cap) override {
std::lock_guard lck(cap_mutex_);
AssertInfo(cap % (8 * sizeof(Type)) == 0,
"Reverse bitset size must be a multiple of {}",
8 * sizeof(Type));
if (cap > cap_) {
data_.resize(cap / (8 * sizeof(Type)));
cap_ = cap;
}
}
public:
int64_t
get_num_rows() const override {
std::shared_lock lck(cap_mutex_);
return cap_;
}
size_t
get_length() const {
std::shared_lock lck(length_mutex_);
return length_;
}
int64_t
get_dim() const override {
return 1;
}
private:
FixedVector<Type> data_{};
// capacity that data_ can store
int64_t cap_;
mutable std::shared_mutex cap_mutex_;
// number of actual elements in data_
size_t length_{};
mutable std::shared_mutex length_mutex_;
};
template <typename Type, bool is_type_entire_row = false>
class FieldDataImpl : public FieldDataBase {
public:
@ -124,8 +236,8 @@ class FieldDataImpl : public FieldDataBase {
FixedVector<Type>&& field_data)
: FieldDataBase(type), dim_(is_type_entire_row ? 1 : dim) {
field_data_ = std::move(field_data);
Assert(field_data.size() % dim == 0);
num_rows_ = field_data.size() / dim;
Assert(field_data_.size() % dim == 0);
num_rows_ = field_data_.size() / dim;
}
void

View File

@ -77,8 +77,8 @@ class ColumnVector final : public BaseVector {
// the size is the number of bits
ColumnVector(TargetBitmap&& bitmap)
: BaseVector(DataType::INT8, bitmap.size()) {
values_ = std::make_shared<FieldDataImpl<uint8_t, false>>(
bitmap.size(), DataType::INT8, std::move(bitmap).into());
values_ = std::make_shared<FieldBitsetImpl<uint8_t>>(DataType::INT8,
std::move(bitmap));
}
virtual ~ColumnVector() override {