mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-11-30 02:48:45 +08:00
Check collection and plan before calling cgo functions (#7733)
Signed-off-by: bigsheeper <yihao.dai@zilliz.com>
This commit is contained in:
parent
c8f860dcfb
commit
0e81c62031
@ -22,6 +22,7 @@ package querynode
|
||||
import "C"
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
@ -30,6 +31,10 @@ type SearchPlan struct {
|
||||
}
|
||||
|
||||
func createSearchPlan(col *Collection, dsl string) (*SearchPlan, error) {
|
||||
if col.collectionPtr == nil {
|
||||
return nil, errors.New("nil collection ptr, collectionID = " + fmt.Sprintln(col.id))
|
||||
}
|
||||
|
||||
cDsl := C.CString(dsl)
|
||||
defer C.free(unsafe.Pointer(cDsl))
|
||||
var cPlan C.CSearchPlan
|
||||
@ -45,6 +50,10 @@ func createSearchPlan(col *Collection, dsl string) (*SearchPlan, error) {
|
||||
}
|
||||
|
||||
func createSearchPlanByExpr(col *Collection, expr []byte) (*SearchPlan, error) {
|
||||
if col.collectionPtr == nil {
|
||||
return nil, errors.New("nil collection ptr, collectionID = " + fmt.Sprintln(col.id))
|
||||
}
|
||||
|
||||
var cPlan C.CSearchPlan
|
||||
status := C.CreateSearchPlanByExpr(col.collectionPtr, (*C.char)(unsafe.Pointer(&expr[0])), (C.int64_t)(len(expr)), &cPlan)
|
||||
|
||||
|
@ -41,6 +41,18 @@ func TestPlan_Plan(t *testing.T) {
|
||||
deleteCollection(collection)
|
||||
}
|
||||
|
||||
func TestPlan_NilCollection(t *testing.T) {
|
||||
collection := &Collection{
|
||||
id: defaultCollectionID,
|
||||
}
|
||||
|
||||
_, err := createSearchPlan(collection, "")
|
||||
assert.Error(t, err)
|
||||
|
||||
_, err = createSearchPlanByExpr(collection, nil)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func TestPlan_PlaceholderGroup(t *testing.T) {
|
||||
collectionID := UniqueID(0)
|
||||
collectionMeta := genTestCollectionMeta(collectionID, false)
|
||||
|
@ -35,6 +35,10 @@ type MarshaledHits struct {
|
||||
}
|
||||
|
||||
func reduceSearchResultsAndFillData(plan *SearchPlan, searchResults []*SearchResult, numSegments int64) error {
|
||||
if plan.cSearchPlan == nil {
|
||||
return errors.New("nil search plan")
|
||||
}
|
||||
|
||||
cSearchResults := make([]C.CSearchResult, 0)
|
||||
for _, res := range searchResults {
|
||||
cSearchResults = append(cSearchResults, res.cSearchResult)
|
||||
|
@ -106,3 +106,9 @@ func TestReduce_AllFunc(t *testing.T) {
|
||||
deleteSegment(segment)
|
||||
deleteCollection(collection)
|
||||
}
|
||||
|
||||
func TestReduce_nilPlan(t *testing.T) {
|
||||
plan := &SearchPlan{}
|
||||
err := reduceSearchResultsAndFillData(plan, nil, 1)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user