Skip to content

Commit

Permalink
test: add go case for groupby search
Browse files Browse the repository at this point in the history
Signed-off-by: ThreadDao <[email protected]>
  • Loading branch information
ThreadDao authored and MrPresent-Han committed Dec 12, 2024
1 parent a970301 commit b70f30c
Show file tree
Hide file tree
Showing 3 changed files with 482 additions and 9 deletions.
21 changes: 12 additions & 9 deletions internal/core/src/exec/operator/groupby/SearchGroupByOperator.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,28 @@ class SealedDataGetter : public DataGetter<T> {
private:
const segcore::SegmentSealed& segment_;
const FieldId field_id_;
bool from_data_;

mutable std::unordered_map<int64_t, std::vector<std::string_view>>
str_view_map_;
// Getting str_view from segment is cpu-costly, this map is to cache this view for performance
public:
SealedDataGetter(const segcore::SegmentSealed& segment, FieldId& field_id)
: segment_(segment), field_id_(field_id) {
from_data_ = segment_.HasFieldData(field_id_);
if (!from_data_ && !segment_.HasIndex(field_id_)) {
PanicInfo(
UnexpectedError,
"The segment:{} used to init data getter has no effective "
"data source, neither"
"index or data",
segment_.get_segment_id());
}
}

T
Get(int64_t idx) const {
if (segment_.HasFieldData(field_id_)) {
if (from_data_) {
auto id_offset_pair = segment_.get_chunk_by_offset(field_id_, idx);
auto chunk_id = id_offset_pair.first;
auto inner_offset = id_offset_pair.second;
Expand All @@ -91,18 +101,11 @@ class SealedDataGetter : public DataGetter<T> {
auto raw = span.operator[](inner_offset);
return raw;
}
} else if (segment_.HasIndex(field_id_)) {
} else {
auto& chunk_index = segment_.chunk_scalar_index<T>(field_id_, 0);
auto raw = chunk_index.Reverse_Lookup(idx);
AssertInfo(raw.has_value(), "field data not found");
return raw.value();
} else {
PanicInfo(
UnexpectedError,
"The segment:{} used to init data getter has no effective "
"data source, neither"
"index or data",
segment_.get_segment_id());
}
}
};
Expand Down
7 changes: 7 additions & 0 deletions internal/core/src/segcore/SegmentSealedImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ class SegmentSealedImpl : public SegmentSealed {

std::pair<int64_t, int64_t>
get_chunk_by_offset(FieldId field_id, int64_t offset) const override {
if (fields_.find(field_id) == fields_.end()) {
PanicInfo(
ErrorCode::FieldIDInvalid,
"Failed to get chunk offset towards a non-existing field:{}",
field_id.get());
}
// for sealed segment, chunk id is always zero and input offset is the target offset
return std::make_pair(0, offset);
}

Expand Down
Loading

0 comments on commit b70f30c

Please sign in to comment.