diff --git a/internal/core/src/common/Utils.h b/internal/core/src/common/Utils.h index bd3216ac2b..301590b9fc 100644 --- a/internal/core/src/common/Utils.h +++ b/internal/core/src/common/Utils.h @@ -12,6 +12,7 @@ #pragma once #include + #include #include "common/Consts.h" @@ -85,14 +86,14 @@ PostfixMatch(const std::string& str, const std::string& postfix) { inline int64_t upper_align(int64_t value, int64_t align) { Assert(align > 0); - auto groups = (value + align - 1) / align; + auto groups = value / align + (value % align != 0); return groups * align; } inline int64_t upper_div(int64_t value, int64_t align) { Assert(align > 0); - auto groups = (value + align - 1) / align; + auto groups = value / align + (value % align != 0); return groups; } diff --git a/internal/core/src/segcore/ConcurrentVector.cpp b/internal/core/src/segcore/ConcurrentVector.cpp index 4d383c1c74..d13748d01e 100644 --- a/internal/core/src/segcore/ConcurrentVector.cpp +++ b/internal/core/src/segcore/ConcurrentVector.cpp @@ -109,10 +109,16 @@ VectorBase::fill_chunk_data(ssize_t element_count, const DataArray* data, const return fill_chunk_data(data->scalars().double_data().data().data(), element_count); } case DataType::VARCHAR: { - auto begin = data->scalars().string_data().data().begin(); - auto end = data->scalars().string_data().data().end(); - std::vector data_raw(begin, end); - return fill_chunk_data(data_raw.data(), element_count); + auto vec = static_cast*>(this); + auto count = data->scalars().string_data().data().size(); + vec->grow_on_demand(count); + auto& chunk = vec->get_chunk(0); + + size_t index = 0; + for (auto& str : data->scalars().string_data().data()) { + chunk[index++] = str; + } + return; } default: { PanicInfo("unsupported"); diff --git a/internal/core/src/segcore/ConcurrentVector.h b/internal/core/src/segcore/ConcurrentVector.h index b824aa21df..3670d8840e 100644 --- a/internal/core/src/segcore/ConcurrentVector.h +++ b/internal/core/src/segcore/ConcurrentVector.h @@ -11,18 +11,18 @@ #pragma once +#include + #include #include #include #include +#include #include #include -#include #include #include -#include - #include "common/FieldMeta.h" #include "common/Span.h" #include "common/Types.h" @@ -148,6 +148,12 @@ class ConcurrentVectorImpl : public VectorBase { chunks_.emplace_to_at_least(chunk_count, Dim * size_per_chunk_); } + void + grow_on_demand(int64_t element_count) { + auto chunk_count = upper_div(element_count, size_per_chunk_); + chunks_.emplace_to_at_least(chunk_count, Dim * element_count); + } + Span get_span(int64_t chunk_id) const { auto& chunk = get_chunk(chunk_id); @@ -224,6 +230,11 @@ class ConcurrentVectorImpl : public VectorBase { return chunks_[chunk_index]; } + Chunk& + get_chunk(ssize_t index) { + return chunks_[index]; + } + const void* get_chunk_data(ssize_t chunk_index) const override { return chunks_[chunk_index].data(); @@ -274,7 +285,7 @@ class ConcurrentVectorImpl : public VectorBase { return; } auto chunk_max_size = chunks_.size(); - Assert(chunk_id < chunk_max_size); + AssertInfo(chunk_id < chunk_max_size, "chunk_id=" + std::to_string(chunk_id)); Chunk& chunk = chunks_[chunk_id]; auto ptr = chunk.data(); std::copy_n(source + source_offset * Dim, element_count * Dim, ptr + chunk_offset * Dim);