mirror of https://github.com/milvus-io/milvus.git
Check dsl whether is None (#5616)
* Check dsl whether is None Signed-off-by: xiaocai2333 <cai.zhang@zilliz.com> * Format code Signed-off-by: xiaocai2333 <cai.zhang@zilliz.com>pull/5624/head^2
parent
45e7d26b01
commit
5037646cbd
|
@ -16,17 +16,16 @@ import (
|
|||
|
||||
ant_ast "github.com/antonmedv/expr/ast"
|
||||
ant_parser "github.com/antonmedv/expr/parser"
|
||||
|
||||
"github.com/milvus-io/milvus/internal/proto/planpb"
|
||||
"github.com/milvus-io/milvus/internal/proto/schemapb"
|
||||
"github.com/milvus-io/milvus/internal/util/typeutil"
|
||||
)
|
||||
|
||||
func parseQueryExpr(schema *typeutil.SchemaHelper, exprStrNullable *string) (*planpb.Expr, error) {
|
||||
if exprStrNullable == nil {
|
||||
func parseQueryExpr(schema *typeutil.SchemaHelper, exprStr string) (*planpb.Expr, error) {
|
||||
if exprStr == "" {
|
||||
return nil, nil
|
||||
}
|
||||
exprStr := *exprStrNullable
|
||||
|
||||
return parseQueryExprAdvanced(schema, exprStr)
|
||||
}
|
||||
|
||||
|
@ -325,13 +324,13 @@ func (context *ParserContext) handleExpr(nodeRaw *ant_ast.Node) (*planpb.Expr, e
|
|||
}
|
||||
}
|
||||
|
||||
func CreateQueryPlan(schemaPb *schemapb.CollectionSchema, exprStrNullable *string, vectorFieldName string, queryInfo *planpb.QueryInfo) (*planpb.PlanNode, error) {
|
||||
func CreateQueryPlan(schemaPb *schemapb.CollectionSchema, exprStr string, vectorFieldName string, queryInfo *planpb.QueryInfo) (*planpb.PlanNode, error) {
|
||||
schema, err := typeutil.CreateSchemaHelper(schemaPb)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
expr, err := parseQueryExpr(schema, exprStrNullable)
|
||||
expr, err := parseQueryExpr(schema, exprStr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ func TestParseQueryExpr_Naive(t *testing.T) {
|
|||
schemaPb := newTestSchema()
|
||||
schema, err := typeutil.CreateSchemaHelper(schemaPb)
|
||||
assert.Nil(t, err)
|
||||
exprProto, err := parseQueryExpr(schema, &exprStr)
|
||||
exprProto, err := parseQueryExpr(schema, exprStr)
|
||||
assert.Nil(t, err)
|
||||
str := proto.MarshalTextString(exprProto)
|
||||
println(str)
|
||||
|
@ -82,7 +82,7 @@ func TestParsePlanNode_Naive(t *testing.T) {
|
|||
// TODO: change it to better solution
|
||||
for offset, exprStr := range exprStrs {
|
||||
fmt.Printf("case %d: %s\n", offset, exprStr)
|
||||
planProto, err := CreateQueryPlan(schema, &exprStr, "FloatVectorField", queryInfo)
|
||||
planProto, err := CreateQueryPlan(schema, exprStr, "FloatVectorField", queryInfo)
|
||||
assert.Nil(t, err)
|
||||
dbgStr := proto.MarshalTextString(planProto)
|
||||
println(dbgStr)
|
||||
|
@ -118,7 +118,7 @@ func TestExprPlan_Str(t *testing.T) {
|
|||
}
|
||||
|
||||
// without filter
|
||||
planProto, err := CreateQueryPlan(schema, nil, "fakevec", queryInfo)
|
||||
planProto, err := CreateQueryPlan(schema, "", "fakevec", queryInfo)
|
||||
assert.Nil(t, err)
|
||||
dbgStr := proto.MarshalTextString(planProto)
|
||||
println(dbgStr)
|
||||
|
@ -130,7 +130,7 @@ func TestExprPlan_Str(t *testing.T) {
|
|||
|
||||
for offset, exprStr := range exprStrs {
|
||||
fmt.Printf("case %d: %s\n", offset, exprStr)
|
||||
planProto, err := CreateQueryPlan(schema, &exprStr, "fakevec", queryInfo)
|
||||
planProto, err := CreateQueryPlan(schema, exprStr, "fakevec", queryInfo)
|
||||
assert.Nil(t, err)
|
||||
dbgStr := proto.MarshalTextString(planProto)
|
||||
println(dbgStr)
|
||||
|
|
|
@ -1063,7 +1063,7 @@ func (st *SearchTask) PreExecute(ctx context.Context) error {
|
|||
SearchParams: searchParams,
|
||||
}
|
||||
|
||||
plan, err := CreateQueryPlan(schema, &st.query.Dsl, annsField, queryInfo)
|
||||
plan, err := CreateQueryPlan(schema, st.query.Dsl, annsField, queryInfo)
|
||||
if err != nil {
|
||||
return errors.New("invalid expression: " + st.query.Dsl)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue