2023-03-16 19:31:55 +08:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2023-06-09 01:28:37 +08:00
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
|
|
|
|
"github.com/milvus-io/milvus-proto/go-api/v2/schemapb"
|
2023-03-16 19:31:55 +08:00
|
|
|
"github.com/milvus-io/milvus/internal/proto/internalpb"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/common"
|
2023-09-04 09:57:09 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/merr"
|
2023-04-06 19:14:32 +08:00
|
|
|
"github.com/milvus-io/milvus/pkg/util/typeutil"
|
2023-03-16 19:31:55 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type defaultLimitReducer struct {
|
|
|
|
ctx context.Context
|
|
|
|
req *internalpb.RetrieveRequest
|
|
|
|
params *queryParams
|
|
|
|
schema *schemapb.CollectionSchema
|
|
|
|
collectionName string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *defaultLimitReducer) Reduce(results []*internalpb.RetrieveResults) (*milvuspb.QueryResults, error) {
|
|
|
|
res, err := reduceRetrieveResultsAndFillIfEmpty(r.ctx, results, r.params, r.req.GetOutputFieldsId(), r.schema)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := r.afterReduce(res); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *defaultLimitReducer) afterReduce(result *milvuspb.QueryResults) error {
|
|
|
|
collectionName := r.collectionName
|
|
|
|
schema := r.schema
|
|
|
|
outputFieldsID := r.req.GetOutputFieldsId()
|
|
|
|
|
|
|
|
result.CollectionName = collectionName
|
2023-10-08 21:23:32 +08:00
|
|
|
var err error
|
2023-03-16 19:31:55 +08:00
|
|
|
|
2023-10-08 21:23:32 +08:00
|
|
|
for i := 0; i < len(result.GetFieldsData()); i++ {
|
|
|
|
// drop ts column
|
2023-03-16 19:31:55 +08:00
|
|
|
if outputFieldsID[i] == common.TimeStampField {
|
|
|
|
result.FieldsData = append(result.FieldsData[:i], result.FieldsData[(i+1):]...)
|
2023-10-08 21:23:32 +08:00
|
|
|
outputFieldsID = append(outputFieldsID[:i], outputFieldsID[i+1:]...)
|
2023-03-16 19:31:55 +08:00
|
|
|
i--
|
|
|
|
continue
|
|
|
|
}
|
2023-10-08 21:23:32 +08:00
|
|
|
field := typeutil.GetField(schema, outputFieldsID[i])
|
|
|
|
if field == nil {
|
|
|
|
err = merr.WrapErrFieldNotFound(outputFieldsID[i])
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if result.FieldsData[i] == nil {
|
|
|
|
result.FieldsData[i], err = typeutil.GenEmptyFieldData(field)
|
|
|
|
if err != nil {
|
|
|
|
break
|
2023-03-16 19:31:55 +08:00
|
|
|
}
|
2023-10-08 21:23:32 +08:00
|
|
|
continue
|
2023-03-16 19:31:55 +08:00
|
|
|
}
|
2023-10-08 21:23:32 +08:00
|
|
|
|
|
|
|
result.FieldsData[i].FieldName = field.GetName()
|
|
|
|
result.FieldsData[i].FieldId = field.GetFieldID()
|
|
|
|
result.FieldsData[i].Type = field.GetDataType()
|
|
|
|
result.FieldsData[i].IsDynamic = field.GetIsDynamic()
|
2023-03-16 19:31:55 +08:00
|
|
|
}
|
|
|
|
|
2023-10-08 21:23:32 +08:00
|
|
|
result.Status = merr.Status(err)
|
|
|
|
return err
|
2023-03-16 19:31:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func newDefaultLimitReducer(ctx context.Context, params *queryParams, req *internalpb.RetrieveRequest, schema *schemapb.CollectionSchema, collectionName string) *defaultLimitReducer {
|
|
|
|
return &defaultLimitReducer{
|
|
|
|
ctx: ctx,
|
|
|
|
req: req,
|
|
|
|
params: params,
|
|
|
|
schema: schema,
|
|
|
|
collectionName: collectionName,
|
|
|
|
}
|
|
|
|
}
|