enhance: Opt metric type does not match error message (#29927)

issue: #29791 
/kind improvement
Signed-off-by: xige-16 <xi.ge@zilliz.com>

Signed-off-by: xige-16 <xi.ge@zilliz.com>
pull/30083/head
xige-16 2024-01-17 20:25:03 +08:00 committed by GitHub
parent 6fd432593c
commit fa7cf587b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 27 additions and 20 deletions

View File

@ -58,7 +58,9 @@ enum ErrorCode {
FieldNotLoaded = 2027,
ExprInvalid = 2028,
UnistdError = 2030,
MetricTypeNotMatch = 2031,
KnowhereError = 2100,
};
namespace impl {
void

View File

@ -281,16 +281,7 @@ class SegmentGrowingImpl : public SegmentGrowing {
void
check_search(const query::Plan* plan) const override {
Assert(plan);
auto& metric_str = plan->plan_node_->search_info_.metric_type_;
auto searched_field_id = plan->plan_node_->search_info_.field_id_;
auto index_meta =
index_meta_->GetFieldIndexMeta(FieldId(searched_field_id));
if (metric_str.empty()) {
metric_str = index_meta.GeMetricType();
} else {
AssertInfo(metric_str == index_meta.GeMetricType(),
"metric type not match");
}
check_metric_type(plan, index_meta_);
}
const ConcurrentVector<Timestamp>&

View File

@ -316,4 +316,23 @@ SegmentInternalInterface::LoadStringSkipIndex(
skipIndex_.LoadString(field_id, chunk_id, var_column);
}
void
SegmentInternalInterface::check_metric_type(
const query::Plan* plan, const IndexMetaPtr index_meta) const {
auto& metric_str = plan->plan_node_->search_info_.metric_type_;
auto searched_field_id = plan->plan_node_->search_info_.field_id_;
auto field_index_meta =
index_meta->GetFieldIndexMeta(FieldId(searched_field_id));
if (metric_str.empty()) {
metric_str = field_index_meta.GeMetricType();
}
if (metric_str != field_index_meta.GeMetricType()) {
throw SegcoreError(
MetricTypeNotMatch,
fmt::format("metric type not match, expected {}, actual {}.",
field_index_meta.GeMetricType(),
metric_str));
}
}
} // namespace milvus::segcore

View File

@ -231,6 +231,10 @@ class SegmentInternalInterface : public SegmentInterface {
virtual std::pair<std::unique_ptr<IdArray>, std::vector<SegOffset>>
search_ids(const IdArray& id_array, Timestamp timestamp) const = 0;
void
check_metric_type(const query::Plan* plan,
const IndexMetaPtr index_meta) const;
/**
* Apply timestamp filtering on bitset, the query can't see an entity whose
* timestamp is bigger than the timestamp of query.

View File

@ -921,16 +921,7 @@ SegmentSealedImpl::check_search(const query::Plan* plan) const {
AssertInfo(plan->extra_info_opt_.has_value(),
"Extra info of search plan doesn't have value");
auto& metric_str = plan->plan_node_->search_info_.metric_type_;
auto searched_field_id = plan->plan_node_->search_info_.field_id_;
auto index_meta =
col_index_meta_->GetFieldIndexMeta(FieldId(searched_field_id));
if (metric_str.empty()) {
metric_str = index_meta.GeMetricType();
} else {
AssertInfo(metric_str == index_meta.GeMetricType(),
"metric type not match");
}
check_metric_type(plan, col_index_meta_);
if (!is_system_field_ready()) {
PanicInfo(