From 5b018576f44f64cca9e0ca58ada3118bcb71cd72 Mon Sep 17 00:00:00 2001 From: Congqi Xia Date: Tue, 13 Aug 2024 19:33:49 +0800 Subject: [PATCH] Fix lint issue Signed-off-by: Congqi Xia --- states/scan_binlog.go | 44 +++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/states/scan_binlog.go b/states/scan_binlog.go index 2ab6748..85befb4 100644 --- a/states/scan_binlog.go +++ b/states/scan_binlog.go @@ -7,14 +7,15 @@ import ( "github.com/cockroachdb/errors" "github.com/expr-lang/expr" + "github.com/minio/minio-go/v7" + "github.com/samber/lo" + "github.com/milvus-io/birdwatcher/framework" "github.com/milvus-io/birdwatcher/models" "github.com/milvus-io/birdwatcher/proto/v2.0/schemapb" "github.com/milvus-io/birdwatcher/states/etcd/common" etcdversion "github.com/milvus-io/birdwatcher/states/etcd/version" "github.com/milvus-io/birdwatcher/storage" - "github.com/minio/minio-go/v7" - "github.com/samber/lo" ) type ScanBinlogParams struct { @@ -44,7 +45,7 @@ func (s *InstanceState) ScanBinlogCommand(ctx context.Context, p *ScanBinlogPara fieldsMap[field] = struct{}{} } - fields := make(map[int64]models.FieldSchema) //make([]models.FieldSchema, 0, len(p.Fields)) + fields := make(map[int64]models.FieldSchema) // make([]models.FieldSchema, 0, len(p.Fields)) for _, fieldSchema := range collection.Schema.Fields { if _, ok := fieldsMap[fieldSchema.Name]; ok { @@ -113,27 +114,30 @@ func (s *InstanceState) ScanBinlogCommand(ctx context.Context, p *ScanBinlogPara } err = s.scanBinlogs(pkObject, fieldObjects, func(pk storage.PrimaryKey, offset int, values map[int64]any) error { - env := lo.MapKeys(values, func(_ any, fid int64) string { - return fields[fid].Name - }) - program, err := expr.Compile(p.Expr, expr.Env(env)) - if err != nil { - return err - } + if len(p.Expr) != 0 { + env := lo.MapKeys(values, func(_ any, fid int64) string { + return fields[fid].Name + }) + program, err := expr.Compile(p.Expr, expr.Env(env)) + if err != nil { + return err + } - output, err := expr.Run(program, env) - if err != nil { - fmt.Println("failed to run expression, err: ", err.Error()) - } + output, err := expr.Run(program, env) + if err != nil { + fmt.Println("failed to run expression, err: ", err.Error()) + } - match, ok := output.(bool) - if !ok { - return errors.Newf("filter expression result not bool but %T", output) - } + match, ok := output.(bool) + if !ok { + return errors.Newf("filter expression result not bool but %T", output) + } - if !match { - return nil + if !match { + return nil + } } + switch strings.ToLower(p.Action) { case "count": count++