mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-04 04:49:08 +08:00
enhance: refine error message for invalid limit parameter (#34179)
pr: #34178 Signed-off-by: jaime <yun.zhang@zilliz.com>
This commit is contained in:
parent
07a05db51b
commit
7f636dbdf6
@ -37,7 +37,7 @@ func parseSearchInfo(searchParamsPair []*commonpb.KeyValuePair, schema *schemapb
|
||||
if err != nil {
|
||||
return nil, 0, fmt.Errorf("%s [%s] is invalid", TopKKey, topKStr)
|
||||
}
|
||||
if err := validateTopKLimit(topK); err != nil {
|
||||
if err := validateLimit(topK); err != nil {
|
||||
return nil, 0, fmt.Errorf("%s [%d] is invalid, %w", TopKKey, topK, err)
|
||||
}
|
||||
|
||||
@ -51,7 +51,7 @@ func parseSearchInfo(searchParamsPair []*commonpb.KeyValuePair, schema *schemapb
|
||||
}
|
||||
|
||||
if offset != 0 {
|
||||
if err := validateTopKLimit(offset); err != nil {
|
||||
if err := validateLimit(offset); err != nil {
|
||||
return nil, 0, fmt.Errorf("%s [%d] is invalid, %w", OffsetKey, offset, err)
|
||||
}
|
||||
}
|
||||
@ -59,7 +59,7 @@ func parseSearchInfo(searchParamsPair []*commonpb.KeyValuePair, schema *schemapb
|
||||
}
|
||||
|
||||
queryTopK := topK + offset
|
||||
if err := validateTopKLimit(queryTopK); err != nil {
|
||||
if err := validateLimit(queryTopK); err != nil {
|
||||
return nil, 0, fmt.Errorf("%s+%s [%d] is invalid, %w", OffsetKey, TopKKey, queryTopK, err)
|
||||
}
|
||||
|
||||
|
@ -109,10 +109,10 @@ func validateMaxQueryResultWindow(offset int64, limit int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateTopKLimit(topK int64) error {
|
||||
func validateLimit(limit int64) error {
|
||||
topKLimit := Params.QuotaConfig.TopKLimit.GetAsInt64()
|
||||
if topK <= 0 || topK > topKLimit {
|
||||
return fmt.Errorf("top k should be in range [1, %d], but got %d", topKLimit, topK)
|
||||
if limit <= 0 || limit > topKLimit {
|
||||
return fmt.Errorf("it should be in range [1, %d], but got %d", topKLimit, limit)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -1947,10 +1947,10 @@ func Test_NQLimit(t *testing.T) {
|
||||
|
||||
func Test_TopKLimit(t *testing.T) {
|
||||
paramtable.Init()
|
||||
assert.Nil(t, validateTopKLimit(16384))
|
||||
assert.Nil(t, validateTopKLimit(1))
|
||||
assert.Error(t, validateTopKLimit(16385))
|
||||
assert.Error(t, validateTopKLimit(0))
|
||||
assert.Nil(t, validateLimit(16384))
|
||||
assert.Nil(t, validateLimit(1))
|
||||
assert.Error(t, validateLimit(16385))
|
||||
assert.Error(t, validateLimit(0))
|
||||
}
|
||||
|
||||
func Test_MaxQueryResultWindow(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user