From 66710008d63c42633acbb785d4b9313513f07819 Mon Sep 17 00:00:00 2001 From: coldWater <254244460@qq.com> Date: Fri, 21 Jun 2024 10:52:02 +0800 Subject: [PATCH] enhance: Support queryOption WithLimit for milvusclient (#33978) See also #31293 --------- Signed-off-by: coldWater <254244460@qq.com> --- client/column/json.go | 2 +- client/read_options.go | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/client/column/json.go b/client/column/json.go index a1c1470897..0471b05548 100644 --- a/client/column/json.go +++ b/client/column/json.go @@ -134,7 +134,7 @@ func (c *ColumnJSONBytes) AppendValue(i interface{}) error { } v = bs default: - return fmt.Errorf("expect json compatible type([]byte, struct[}, map], got %T)", i) + return fmt.Errorf("expect json compatible type([]byte, struct, map), got %T", i) } } c.values = append(c.values, v) diff --git a/client/read_options.go b/client/read_options.go index bd04c62953..152061b1a0 100644 --- a/client/read_options.go +++ b/client/read_options.go @@ -31,6 +31,7 @@ const ( spAnnsField = `anns_field` spTopK = `topk` spOffset = `offset` + spLimit = `limit` spParams = `params` spMetricsType = `metric_type` spRoundDecimal = `round_decimal` @@ -197,15 +198,12 @@ type QueryOption interface { } type queryOption struct { - collectionName string - partitionNames []string - - limit int - offset int + collectionName string + partitionNames []string + queryParams map[string]string outputFields []string consistencyLevel entity.ConsistencyLevel useDefaultConsistencyLevel bool - ignoreGrowing bool expr string } @@ -216,6 +214,7 @@ func (opt *queryOption) Request() *milvuspb.QueryRequest { OutputFields: opt.outputFields, Expr: opt.expr, + QueryParams: entity.MapKvPairs(opt.queryParams), ConsistencyLevel: opt.consistencyLevel.CommonConsistencyLevel(), } } @@ -226,7 +225,18 @@ func (opt *queryOption) WithFilter(expr string) *queryOption { } func (opt *queryOption) WithOffset(offset int) *queryOption { - opt.offset = offset + if opt.queryParams == nil { + opt.queryParams = make(map[string]string) + } + opt.queryParams[spOffset] = strconv.Itoa(offset) + return opt +} + +func (opt *queryOption) WithLimit(limit int) *queryOption { + if opt.queryParams == nil { + opt.queryParams = make(map[string]string) + } + opt.queryParams[spLimit] = strconv.Itoa(limit) return opt }