mirror of https://github.com/milvus-io/milvus.git
Fix golint warning of plan_parser.go (#9827)
Signed-off-by: dragondriver <jiquan.long@zilliz.com>pull/9832/head
parent
e97b62cf67
commit
8f5bf46705
|
@ -23,7 +23,7 @@ import (
|
||||||
"github.com/milvus-io/milvus/internal/util/typeutil"
|
"github.com/milvus-io/milvus/internal/util/typeutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ParserContext struct {
|
type parserContext struct {
|
||||||
schema *typeutil.SchemaHelper
|
schema *typeutil.SchemaHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ func parseExpr(schema *typeutil.SchemaHelper, exprStr string) (*planpb.Expr, err
|
||||||
return nil, optimizer.err
|
return nil, optimizer.err
|
||||||
}
|
}
|
||||||
|
|
||||||
pc := ParserContext{schema}
|
pc := parserContext{schema}
|
||||||
expr, err := pc.handleExpr(&ast.Node)
|
expr, err := pc.handleExpr(&ast.Node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -270,7 +270,7 @@ func parseBoolNode(nodeRaw *ant_ast.Node) *ant_ast.BoolNode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *ParserContext) createCmpExpr(left, right ant_ast.Node, operator string) (*planpb.Expr, error) {
|
func (pc *parserContext) createCmpExpr(left, right ant_ast.Node, operator string) (*planpb.Expr, error) {
|
||||||
if boolNode := parseBoolNode(&left); boolNode != nil {
|
if boolNode := parseBoolNode(&left); boolNode != nil {
|
||||||
left = boolNode
|
left = boolNode
|
||||||
}
|
}
|
||||||
|
@ -347,11 +347,11 @@ func (pc *ParserContext) createCmpExpr(left, right ant_ast.Node, operator string
|
||||||
return expr, nil
|
return expr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *ParserContext) handleCmpExpr(node *ant_ast.BinaryNode) (*planpb.Expr, error) {
|
func (pc *parserContext) handleCmpExpr(node *ant_ast.BinaryNode) (*planpb.Expr, error) {
|
||||||
return pc.createCmpExpr(node.Left, node.Right, node.Operator)
|
return pc.createCmpExpr(node.Left, node.Right, node.Operator)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *ParserContext) handleLogicalExpr(node *ant_ast.BinaryNode) (*planpb.Expr, error) {
|
func (pc *parserContext) handleLogicalExpr(node *ant_ast.BinaryNode) (*planpb.Expr, error) {
|
||||||
op := getLogicalOpType(node.Operator)
|
op := getLogicalOpType(node.Operator)
|
||||||
if op == planpb.BinaryExpr_Invalid {
|
if op == planpb.BinaryExpr_Invalid {
|
||||||
return nil, fmt.Errorf("invalid logical operator(%s)", node.Operator)
|
return nil, fmt.Errorf("invalid logical operator(%s)", node.Operator)
|
||||||
|
@ -379,7 +379,7 @@ func (pc *ParserContext) handleLogicalExpr(node *ant_ast.BinaryNode) (*planpb.Ex
|
||||||
return expr, nil
|
return expr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *ParserContext) handleArrayExpr(node *ant_ast.Node, dataType schemapb.DataType) ([]*planpb.GenericValue, error) {
|
func (pc *parserContext) handleArrayExpr(node *ant_ast.Node, dataType schemapb.DataType) ([]*planpb.GenericValue, error) {
|
||||||
arrayNode, ok2 := (*node).(*ant_ast.ArrayNode)
|
arrayNode, ok2 := (*node).(*ant_ast.ArrayNode)
|
||||||
if !ok2 {
|
if !ok2 {
|
||||||
return nil, fmt.Errorf("right operand of the InExpr must be array")
|
return nil, fmt.Errorf("right operand of the InExpr must be array")
|
||||||
|
@ -397,7 +397,7 @@ func (pc *ParserContext) handleArrayExpr(node *ant_ast.Node, dataType schemapb.D
|
||||||
return arr, nil
|
return arr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *ParserContext) handleInExpr(node *ant_ast.BinaryNode) (*planpb.Expr, error) {
|
func (pc *parserContext) handleInExpr(node *ant_ast.BinaryNode) (*planpb.Expr, error) {
|
||||||
if node.Operator != "in" && node.Operator != "not in" {
|
if node.Operator != "in" && node.Operator != "not in" {
|
||||||
return nil, fmt.Errorf("invalid operator(%s)", node.Operator)
|
return nil, fmt.Errorf("invalid operator(%s)", node.Operator)
|
||||||
}
|
}
|
||||||
|
@ -429,7 +429,7 @@ func (pc *ParserContext) handleInExpr(node *ant_ast.BinaryNode) (*planpb.Expr, e
|
||||||
return expr, nil
|
return expr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *ParserContext) combineUnaryRangeExpr(a, b *planpb.UnaryRangeExpr) *planpb.Expr {
|
func (pc *parserContext) combineUnaryRangeExpr(a, b *planpb.UnaryRangeExpr) *planpb.Expr {
|
||||||
if a.Op == planpb.OpType_LessEqual || a.Op == planpb.OpType_LessThan {
|
if a.Op == planpb.OpType_LessEqual || a.Op == planpb.OpType_LessThan {
|
||||||
a, b = b, a
|
a, b = b, a
|
||||||
}
|
}
|
||||||
|
@ -451,7 +451,7 @@ func (pc *ParserContext) combineUnaryRangeExpr(a, b *planpb.UnaryRangeExpr) *pla
|
||||||
return expr
|
return expr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *ParserContext) handleMultiCmpExpr(node *ant_ast.BinaryNode) (*planpb.Expr, error) {
|
func (pc *parserContext) handleMultiCmpExpr(node *ant_ast.BinaryNode) (*planpb.Expr, error) {
|
||||||
exprs := []*planpb.Expr{}
|
exprs := []*planpb.Expr{}
|
||||||
curNode := node
|
curNode := node
|
||||||
|
|
||||||
|
@ -511,7 +511,7 @@ func (pc *ParserContext) handleMultiCmpExpr(node *ant_ast.BinaryNode) (*planpb.E
|
||||||
return combinedExpr, nil
|
return combinedExpr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *ParserContext) handleBinaryExpr(node *ant_ast.BinaryNode) (*planpb.Expr, error) {
|
func (pc *parserContext) handleBinaryExpr(node *ant_ast.BinaryNode) (*planpb.Expr, error) {
|
||||||
switch node.Operator {
|
switch node.Operator {
|
||||||
case "<", "<=", ">", ">=":
|
case "<", "<=", ">", ">=":
|
||||||
return pc.handleMultiCmpExpr(node)
|
return pc.handleMultiCmpExpr(node)
|
||||||
|
@ -525,7 +525,7 @@ func (pc *ParserContext) handleBinaryExpr(node *ant_ast.BinaryNode) (*planpb.Exp
|
||||||
return nil, fmt.Errorf("unsupported binary operator %s", node.Operator)
|
return nil, fmt.Errorf("unsupported binary operator %s", node.Operator)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *ParserContext) createNotExpr(childExpr *planpb.Expr) (*planpb.Expr, error) {
|
func (pc *parserContext) createNotExpr(childExpr *planpb.Expr) (*planpb.Expr, error) {
|
||||||
expr := &planpb.Expr{
|
expr := &planpb.Expr{
|
||||||
Expr: &planpb.Expr_UnaryExpr{
|
Expr: &planpb.Expr_UnaryExpr{
|
||||||
UnaryExpr: &planpb.UnaryExpr{
|
UnaryExpr: &planpb.UnaryExpr{
|
||||||
|
@ -537,7 +537,7 @@ func (pc *ParserContext) createNotExpr(childExpr *planpb.Expr) (*planpb.Expr, er
|
||||||
return expr, nil
|
return expr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *ParserContext) handleLeafValue(nodeRaw *ant_ast.Node, dataType schemapb.DataType) (gv *planpb.GenericValue, err error) {
|
func (pc *parserContext) handleLeafValue(nodeRaw *ant_ast.Node, dataType schemapb.DataType) (gv *planpb.GenericValue, err error) {
|
||||||
switch node := (*nodeRaw).(type) {
|
switch node := (*nodeRaw).(type) {
|
||||||
case *ant_ast.FloatNode:
|
case *ant_ast.FloatNode:
|
||||||
if typeutil.IsFloatingType(dataType) {
|
if typeutil.IsFloatingType(dataType) {
|
||||||
|
@ -591,13 +591,13 @@ func (pc *ParserContext) handleLeafValue(nodeRaw *ant_ast.Node, dataType schemap
|
||||||
return gv, nil
|
return gv, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *ParserContext) handleIdentifier(node *ant_ast.IdentifierNode) (*schemapb.FieldSchema, error) {
|
func (pc *parserContext) handleIdentifier(node *ant_ast.IdentifierNode) (*schemapb.FieldSchema, error) {
|
||||||
fieldName := node.Value
|
fieldName := node.Value
|
||||||
field, err := pc.schema.GetFieldFromName(fieldName)
|
field, err := pc.schema.GetFieldFromName(fieldName)
|
||||||
return field, err
|
return field, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *ParserContext) handleUnaryExpr(node *ant_ast.UnaryNode) (*planpb.Expr, error) {
|
func (pc *parserContext) handleUnaryExpr(node *ant_ast.UnaryNode) (*planpb.Expr, error) {
|
||||||
switch node.Operator {
|
switch node.Operator {
|
||||||
case "!", "not":
|
case "!", "not":
|
||||||
subExpr, err := pc.handleExpr(&node.Node)
|
subExpr, err := pc.handleExpr(&node.Node)
|
||||||
|
@ -610,7 +610,7 @@ func (pc *ParserContext) handleUnaryExpr(node *ant_ast.UnaryNode) (*planpb.Expr,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pc *ParserContext) handleExpr(nodeRaw *ant_ast.Node) (*planpb.Expr, error) {
|
func (pc *parserContext) handleExpr(nodeRaw *ant_ast.Node) (*planpb.Expr, error) {
|
||||||
switch node := (*nodeRaw).(type) {
|
switch node := (*nodeRaw).(type) {
|
||||||
case *ant_ast.IdentifierNode,
|
case *ant_ast.IdentifierNode,
|
||||||
*ant_ast.FloatNode,
|
*ant_ast.FloatNode,
|
||||||
|
@ -630,7 +630,7 @@ func (pc *ParserContext) handleExpr(nodeRaw *ant_ast.Node) (*planpb.Expr, error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateQueryPlan(schemaPb *schemapb.CollectionSchema, exprStr 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)
|
schema, err := typeutil.CreateSchemaHelper(schemaPb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -665,7 +665,7 @@ func CreateQueryPlan(schemaPb *schemapb.CollectionSchema, exprStr string, vector
|
||||||
return planNode, nil
|
return planNode, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateExprPlan(schemaPb *schemapb.CollectionSchema, exprStr string) (*planpb.PlanNode, error) {
|
func createExprPlan(schemaPb *schemapb.CollectionSchema, exprStr string) (*planpb.PlanNode, error) {
|
||||||
schema, err := typeutil.CreateSchemaHelper(schemaPb)
|
schema, err := typeutil.CreateSchemaHelper(schemaPb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
@ -175,7 +175,7 @@ func TestParsePlanNode_Naive(t *testing.T) {
|
||||||
// TODO: change it to better solution
|
// TODO: change it to better solution
|
||||||
for offset, exprStr := range exprStrs {
|
for offset, exprStr := range exprStrs {
|
||||||
fmt.Printf("case %d: %s\n", offset, exprStr)
|
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)
|
assert.Nil(t, err)
|
||||||
dbgStr := proto.MarshalTextString(planProto)
|
dbgStr := proto.MarshalTextString(planProto)
|
||||||
println(dbgStr)
|
println(dbgStr)
|
||||||
|
@ -211,7 +211,7 @@ func TestExprPlan_Str(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// without filter
|
// without filter
|
||||||
planProto, err := CreateQueryPlan(schema, "", "fakevec", queryInfo)
|
planProto, err := createQueryPlan(schema, "", "fakevec", queryInfo)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
dbgStr := proto.MarshalTextString(planProto)
|
dbgStr := proto.MarshalTextString(planProto)
|
||||||
println(dbgStr)
|
println(dbgStr)
|
||||||
|
@ -224,7 +224,7 @@ func TestExprPlan_Str(t *testing.T) {
|
||||||
|
|
||||||
for offset, exprStr := range exprStrs {
|
for offset, exprStr := range exprStrs {
|
||||||
fmt.Printf("case %d: %s\n", offset, exprStr)
|
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)
|
assert.Nil(t, err)
|
||||||
dbgStr := proto.MarshalTextString(planProto)
|
dbgStr := proto.MarshalTextString(planProto)
|
||||||
println(dbgStr)
|
println(dbgStr)
|
||||||
|
@ -273,7 +273,7 @@ func TestExprMultiRange_Str(t *testing.T) {
|
||||||
|
|
||||||
for offset, exprStr := range exprStrs {
|
for offset, exprStr := range exprStrs {
|
||||||
fmt.Printf("case %d: %s\n", offset, exprStr)
|
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)
|
assert.Nil(t, err)
|
||||||
dbgStr := proto.MarshalTextString(planProto)
|
dbgStr := proto.MarshalTextString(planProto)
|
||||||
println(dbgStr)
|
println(dbgStr)
|
||||||
|
@ -308,7 +308,7 @@ func TestExprFieldCompare_Str(t *testing.T) {
|
||||||
|
|
||||||
for offset, exprStr := range exprStrs {
|
for offset, exprStr := range exprStrs {
|
||||||
fmt.Printf("case %d: %s\n", offset, exprStr)
|
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)
|
assert.Nil(t, err)
|
||||||
dbgStr := proto.MarshalTextString(planProto)
|
dbgStr := proto.MarshalTextString(planProto)
|
||||||
println(dbgStr)
|
println(dbgStr)
|
||||||
|
|
|
@ -1551,7 +1551,7 @@ func (st *searchTask) PreExecute(ctx context.Context) error {
|
||||||
zap.String("anns field", annsField),
|
zap.String("anns field", annsField),
|
||||||
zap.Any("query info", queryInfo))
|
zap.Any("query info", queryInfo))
|
||||||
|
|
||||||
plan, err := CreateQueryPlan(schema, st.query.Dsl, annsField, queryInfo)
|
plan, err := createQueryPlan(schema, st.query.Dsl, annsField, queryInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("failed to create query plan",
|
log.Debug("failed to create query plan",
|
||||||
zap.Error(err),
|
zap.Error(err),
|
||||||
|
@ -2243,7 +2243,7 @@ func (qt *queryTask) PreExecute(ctx context.Context) error {
|
||||||
return fmt.Errorf(errMsg)
|
return fmt.Errorf(errMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
plan, err := CreateExprPlan(schema, qt.query.Expr)
|
plan, err := createExprPlan(schema, qt.query.Expr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -4644,7 +4644,7 @@ func getPrimaryKeysFromExpr(schema *schemapb.CollectionSchema, expr string) (res
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
plan, err := CreateExprPlan(schema, expr)
|
plan, err := createExprPlan(schema, expr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, fmt.Errorf("failed to create expr plan, expr = %s", expr)
|
return res, fmt.Errorf("failed to create expr plan, expr = %s", expr)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue