Skip to content
Snippets Groups Projects
Select Git revision
  • 1a1e864709d6ffc4d7b112220bf9e30343499c07
  • master default protected
  • benchmark protected
  • v2.0.0-rc4
  • v2.0.0-rc2
  • v2.0.0-rc1
  • v1.1.1
  • v1.1.0
  • v1.0.0
  • v0.10.6
  • v0.10.5
  • v0.10.4
  • v0.10.3
  • v0.10.2
  • v0.10.1
  • v0.8.1
  • v0.10.0
  • v0.9.1
  • v0.9.0
  • v0.8.0
  • v0.7.1
  • v0.7.0
  • v0.6.0
23 results

plan.go

Blame
  • plan.go 2.29 KiB
    package querynode
    
    /*
    #cgo CFLAGS: -I${SRCDIR}/../core/output/include
    #cgo LDFLAGS: -L${SRCDIR}/../core/output/lib -lmilvus_segcore -Wl,-rpath=${SRCDIR}/../core/output/lib
    
    #include "segcore/collection_c.h"
    #include "segcore/segment_c.h"
    #include "segcore/plan_c.h"
    */
    import "C"
    import (
    	"strconv"
    	"unsafe"
    
    	"errors"
    )
    
    type Plan struct {
    	cPlan C.CPlan
    }
    
    func createPlan(col Collection, dsl string) (*Plan, error) {
    	cDsl := C.CString(dsl)
    	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))
    		return nil, errors.New("Create plan failed, C runtime error detected, error code = " + strconv.Itoa(int(errorCode)) + ", error msg = " + errorMsg)
    	}
    
    	var newPlan = &Plan{cPlan: cPlan}
    	return newPlan, nil
    }
    
    func (plan *Plan) getTopK() int64 {
    	topK := C.GetTopK(plan.cPlan)
    	return int64(topK)
    }
    
    func (plan *Plan) getMetricType() string {
    	cMetricType := C.GetMetricType(plan.cPlan)
    	defer C.free(unsafe.Pointer(cMetricType))
    	metricType := C.GoString(cMetricType)
    	return metricType
    }
    
    func (plan *Plan) delete() {
    	C.DeletePlan(plan.cPlan)
    }
    
    type PlaceholderGroup struct {
    	cPlaceholderGroup C.CPlaceholderGroup
    }
    
    func parserPlaceholderGroup(plan *Plan, placeHolderBlob []byte) (*PlaceholderGroup, error) {
    	if len(placeHolderBlob) == 0 {
    		return nil, errors.New("empty search request")
    	}
    	var blobPtr = unsafe.Pointer(&placeHolderBlob[0])
    	blobSize := C.long(len(placeHolderBlob))
    	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))
    		return nil, errors.New("Parser placeholder group failed, C runtime error detected, error code = " + strconv.Itoa(int(errorCode)) + ", error msg = " + errorMsg)
    	}
    
    	var newPlaceholderGroup = &PlaceholderGroup{cPlaceholderGroup: cPlaceholderGroup}
    	return newPlaceholderGroup, nil
    }
    
    func (pg *PlaceholderGroup) getNumOfQuery() int64 {
    	numQueries := C.GetNumOfQueries(pg.cPlaceholderGroup)
    	return int64(numQueries)
    }
    
    func (pg *PlaceholderGroup) delete() {
    	C.DeletePlaceholderGroup(pg.cPlaceholderGroup)
    }