2020-11-26 16:01:31 +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 (
|
2020-11-30 17:58:23 +08:00
|
|
|
"errors"
|
|
|
|
"strconv"
|
2020-11-17 10:07:42 +08:00
|
|
|
"unsafe"
|
|
|
|
)
|
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)
|
|
|
|
|
|
|
|
errorCode := status.error_code
|
|
|
|
|
|
|
|
if errorCode != 0 {
|
|
|
|
errorMsg := C.GoString(status.error_msg)
|
|
|
|
defer C.free(unsafe.Pointer(status.error_msg))
|
2020-12-03 19:00:11 +08:00
|
|
|
return nil, errors.New("Create plan failed, C runtime error detected, error code = " + strconv.Itoa(int(errorCode)) + ", error msg = " + errorMsg)
|
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) {
|
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)
|
|
|
|
|
|
|
|
errorCode := status.error_code
|
|
|
|
|
|
|
|
if errorCode != 0 {
|
|
|
|
errorMsg := C.GoString(status.error_msg)
|
|
|
|
defer C.free(unsafe.Pointer(status.error_msg))
|
2020-12-03 19:00:11 +08:00
|
|
|
return nil, errors.New("Parser placeholder group failed, C runtime error detected, error code = " + strconv.Itoa(int(errorCode)) + ", error msg = " + errorMsg)
|
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
|
|
|
}
|