mirror of
https://github.com/milvus-io/milvus.git
synced 2026-07-21 10:15:43 +00:00
related: #46826 Signed-off-by: MrPresent-Han <chun.han@gmail.com> Co-authored-by: MrPresent-Han <chun.han@gmail.com>
This commit is contained in:
co-authored by
MrPresent-Han
parent
8c2864bfea
commit
ce55d128d5
@@ -139,6 +139,9 @@ class ThreadSafeChunkVector : public ChunkVectorBase<Type> {
|
||||
src.length(),
|
||||
src.byte_size(),
|
||||
src.get_element_type());
|
||||
} else if constexpr (std::is_same_v<Json, Type>) {
|
||||
return Json(chunk[chunk_offset].c_str(),
|
||||
chunk[chunk_offset].size());
|
||||
} else {
|
||||
return chunk[chunk_offset];
|
||||
}
|
||||
|
||||
@@ -1441,22 +1441,10 @@ SegmentGrowingImpl::bulk_subscript_ptr_impl(
|
||||
google::protobuf::RepeatedPtrField<std::string>* dst) const {
|
||||
auto vec = dynamic_cast<const ConcurrentVector<S>*>(vec_raw);
|
||||
auto& src = *vec;
|
||||
if constexpr (std::is_same_v<S, Json>) {
|
||||
// For Json type, we must use operator[] instead of view_element()
|
||||
// to ensure the Json object lives long enough. view_element() returns
|
||||
// a string_view that may point to memory owned by a temporary Json
|
||||
// object, which gets destroyed before we can construct std::string.
|
||||
// Using operator[] copies the Json object, extending its lifetime.
|
||||
for (int64_t i = 0; i < count; ++i) {
|
||||
auto offset = seg_offsets[i];
|
||||
Json json = src[offset]; // Copy Json object to extend lifetime
|
||||
dst->at(i) = std::string(json.data());
|
||||
}
|
||||
} else {
|
||||
for (int64_t i = 0; i < count; ++i) {
|
||||
auto offset = seg_offsets[i];
|
||||
dst->at(i) = std::string(src.view_element(offset));
|
||||
}
|
||||
for (int64_t i = 0; i < count; ++i) {
|
||||
auto offset = seg_offsets[i];
|
||||
auto view = src.view_element(offset);
|
||||
dst->at(i).assign(view.data(), view.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user