2021-01-16 10:12:14 +08:00
|
|
|
package querynode
|
2020-11-09 16:27:11 +08:00
|
|
|
|
2020-11-17 10:07:42 +08:00
|
|
|
/*
|
|
|
|
#cgo CFLAGS: -I${SRCDIR}/../core/output/include
|
|
|
|
#cgo LDFLAGS: -L${SRCDIR}/../core/output/lib -lmilvus_segcore -Wl,-rpath=${SRCDIR}/../core/output/lib
|
2020-11-26 16:01:31 +08:00
|
|
|
|
2020-11-25 10:31:51 +08:00
|
|
|
#include "segcore/collection_c.h"
|
|
|
|
#include "segcore/segment_c.h"
|
|
|
|
#include "segcore/plan_c.h"
|
2020-11-17 10:07:42 +08:00
|
|
|
*/
|
2020-11-09 16:27:11 +08:00
|
|
|
import "C"
|
2020-11-17 10:07:42 +08:00
|
|
|
import (
|
|
|
|
"unsafe"
|
2021-03-05 10:15:27 +08:00
|
|
|
|
|
|
|
"errors"
|
2020-11-17 10:07:42 +08:00
|
|
|
)
|
2020-11-09 16:27:11 +08:00
|
|
|
|
2020-11-17 10:07:42 +08:00
|
|
|
type Plan struct {
|
|
|
|
cPlan C.CPlan
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
|
2020-11-30 17:58:23 +08:00
|
|
|
func createPlan(col Collection, dsl string) (*Plan, error) {
|
2020-11-17 10:07:42 +08:00
|
|
|
cDsl := C.CString(dsl)
|
2020-11-30 17:58:23 +08:00
|
|
|
var cPlan C.CPlan
|
|
|
|
status := C.CreatePlan(col.collectionPtr, cDsl, &cPlan)
|
|
|
|
|
2021-03-26 16:18:30 +08:00
|
|
|
if err := HandleCStatus(&status, "Create Plan failed"); err != nil {
|
|
|
|
return nil, err
|
2020-11-30 17:58:23 +08:00
|
|
|
}
|
|
|
|
|
2020-11-17 10:07:42 +08:00
|
|
|
var newPlan = &Plan{cPlan: cPlan}
|
2020-11-30 17:58:23 +08:00
|
|
|
return newPlan, nil
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|
|
|
|
|
2020-11-26 16:01:31 +08:00
|
|
|
func (plan *Plan) getTopK() int64 {
|
2020-11-17 10:07:42 +08:00
|
|
|
topK := C.GetTopK(plan.cPlan)
|
|
|
|
return int64(topK)
|
|
|
|
}
|
|
|
|
|
2020-12-27 09:05:24 +08:00
|
|
|
func (plan *Plan) getMetricType() string {
|
|
|
|
cMetricType := C.GetMetricType(plan.cPlan)
|
|
|
|
defer C.free(unsafe.Pointer(cMetricType))
|
|
|
|
metricType := C.GoString(cMetricType)
|
|
|
|
return metricType
|
|
|
|
}
|
|
|
|
|
2020-11-26 16:01:31 +08:00
|
|
|
func (plan *Plan) delete() {
|
2020-11-17 10:07:42 +08:00
|
|
|
C.DeletePlan(plan.cPlan)
|
|
|
|
}
|
2020-11-09 16:27:11 +08:00
|
|
|
|
2020-11-17 10:07:42 +08:00
|
|
|
type PlaceholderGroup struct {
|
|
|
|
cPlaceholderGroup C.CPlaceholderGroup
|
|
|
|
}
|
2020-11-09 16:27:11 +08:00
|
|
|
|
2020-11-30 17:58:23 +08:00
|
|
|
func parserPlaceholderGroup(plan *Plan, placeHolderBlob []byte) (*PlaceholderGroup, error) {
|
2021-03-22 19:20:56 +08:00
|
|
|
if len(placeHolderBlob) == 0 {
|
|
|
|
return nil, errors.New("empty search request")
|
|
|
|
}
|
2020-11-17 10:07:42 +08:00
|
|
|
var blobPtr = unsafe.Pointer(&placeHolderBlob[0])
|
|
|
|
blobSize := C.long(len(placeHolderBlob))
|
2020-11-30 17:58:23 +08:00
|
|
|
var cPlaceholderGroup C.CPlaceholderGroup
|
|
|
|
status := C.ParsePlaceholderGroup(plan.cPlan, blobPtr, blobSize, &cPlaceholderGroup)
|
|
|
|
|
2021-03-26 16:18:30 +08:00
|
|
|
if err := HandleCStatus(&status, "parser placeholder group failed"); err != nil {
|
|
|
|
return nil, err
|
2020-11-30 17:58:23 +08:00
|
|
|
}
|
|
|
|
|
2020-11-17 10:07:42 +08:00
|
|
|
var newPlaceholderGroup = &PlaceholderGroup{cPlaceholderGroup: cPlaceholderGroup}
|
2020-11-30 17:58:23 +08:00
|
|
|
return newPlaceholderGroup, nil
|
2020-11-17 10:07:42 +08:00
|
|
|
}
|
2020-11-09 16:27:11 +08:00
|
|
|
|
2020-11-26 16:01:31 +08:00
|
|
|
func (pg *PlaceholderGroup) getNumOfQuery() int64 {
|
2020-11-17 10:07:42 +08:00
|
|
|
numQueries := C.GetNumOfQueries(pg.cPlaceholderGroup)
|
|
|
|
return int64(numQueries)
|
|
|
|
}
|
2020-11-09 16:27:11 +08:00
|
|
|
|
2020-11-26 16:01:31 +08:00
|
|
|
func (pg *PlaceholderGroup) delete() {
|
2020-11-17 10:07:42 +08:00
|
|
|
C.DeletePlaceholderGroup(pg.cPlaceholderGroup)
|
2020-11-09 16:27:11 +08:00
|
|
|
}
|