Browse Source

refactor: rm unused vars

Signed-off-by: xjasonlyu <xjasonlyu@gmail.com>
xjasonlyu 1 year ago
parent
commit
549e351d03

+ 3 - 4
cmd/kuiper/main.go

@@ -1,4 +1,4 @@
-// Copyright 2021-2022 EMQ Technologies Co., Ltd.
+// Copyright 2021-2023 EMQ Technologies Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -24,10 +24,11 @@ import (
 	"strings"
 	"time"
 
+	"github.com/urfave/cli"
+
 	"github.com/lf-edge/ekuiper/internal/conf"
 	"github.com/lf-edge/ekuiper/internal/pkg/model"
 	"github.com/lf-edge/ekuiper/pkg/infra"
-	"github.com/urfave/cli"
 )
 
 type clientConf struct {
@@ -101,14 +102,12 @@ func main() {
 			Usage:   "query command line",
 			Action: func(c *cli.Context) error {
 				reader := bufio.NewReader(os.Stdin)
-				var inputs []string
 				ticker := time.NewTicker(time.Millisecond * 300)
 				defer ticker.Stop()
 				for {
 					fmt.Print("kuiper > ")
 
 					text, _ := reader.ReadString('\n')
-					inputs = append(inputs, text)
 					// convert CRLF to LF
 					text = strings.Replace(text, "\n", "", -1)
 

+ 3 - 4
internal/processor/ruleset.go

@@ -1,4 +1,4 @@
-// Copyright 2022 EMQ Technologies Co., Ltd.
+// Copyright 2022-2023 EMQ Technologies Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -18,8 +18,9 @@ import (
 	"bytes"
 	"encoding/json"
 	"fmt"
-	"github.com/lf-edge/ekuiper/internal/conf"
 	"io"
+
+	"github.com/lf-edge/ekuiper/internal/conf"
 )
 
 type RulesetProcessor struct {
@@ -175,7 +176,6 @@ func (rs *RulesetProcessor) ImportRuleSet(all Ruleset) Ruleset {
 		}
 		counts[1]++
 	}
-	var rules []string
 	// restore rules
 	for k, v := range all.Rules {
 		_, e := rs.r.ExecCreateWithValidation(k, v)
@@ -185,7 +185,6 @@ func (rs *RulesetProcessor) ImportRuleSet(all Ruleset) Ruleset {
 			ruleSetRsp.Rules[k] = e.Error()
 			continue
 		}
-		rules = append(rules, k)
 		counts[2]++
 	}
 	return ruleSetRsp

+ 7 - 5
internal/topo/lookup/cache/cache_test.go

@@ -15,12 +15,14 @@
 package cache
 
 import (
-	"github.com/benbjohnson/clock"
-	"github.com/lf-edge/ekuiper/internal/conf"
-	"github.com/lf-edge/ekuiper/pkg/api"
 	"reflect"
 	"testing"
 	"time"
+
+	"github.com/benbjohnson/clock"
+
+	"github.com/lf-edge/ekuiper/internal/conf"
+	"github.com/lf-edge/ekuiper/pkg/api"
 )
 
 func TestExpiration(t *testing.T) {
@@ -60,7 +62,7 @@ func TestExpiration(t *testing.T) {
 	}
 
 	clock.Add(10 * time.Second)
-	r1, ok = c.Get("a")
+	_, ok = c.Get("a")
 	if ok {
 		t.Error("a should not exist after expiration")
 		return
@@ -74,7 +76,7 @@ func TestExpiration(t *testing.T) {
 		t.Errorf("expect %v but get %v", expects[1], r2)
 	}
 	clock.Add(10 * time.Second)
-	r2, ok = c.Get("b")
+	_, ok = c.Get("b")
 	if ok {
 		t.Error("b should not exist after expiration")
 		return

+ 6 - 5
internal/topo/node/cache/sync_cache.go

@@ -15,15 +15,16 @@
 package cache
 
 import (
+	"path"
+	"strconv"
+	"time"
+
 	"github.com/lf-edge/ekuiper/internal/conf"
 	"github.com/lf-edge/ekuiper/internal/pkg/store"
 	"github.com/lf-edge/ekuiper/internal/topo/node/metric"
 	"github.com/lf-edge/ekuiper/pkg/api"
 	"github.com/lf-edge/ekuiper/pkg/infra"
 	"github.com/lf-edge/ekuiper/pkg/kv"
-	"path"
-	"strconv"
-	"time"
 )
 
 type AckResult bool
@@ -366,12 +367,12 @@ func (c *SyncCache) initStore(ctx api.StreamContext) {
 	if !c.cacheConf.CleanCacheAtStop {
 		// Save 0 when init and save 1 when close. Wait for close for newly started sink node
 		var set int
-		ok, err := c.store.Get("storeSig", &set)
+		ok, _ := c.store.Get("storeSig", &set)
 		if ok && set == 0 { // may be saving
 			var i = 0
 			for ; i < 100; i++ {
 				time.Sleep(time.Millisecond * 10)
-				_, err = c.store.Get("storeSig", &set)
+				c.store.Get("storeSig", &set)
 				if set == 1 {
 					ctx.GetLogger().Infof("waiting for previous cache for %d times", i)
 					break

+ 8 - 7
internal/topo/node/cache/sync_cache_test.go

@@ -16,17 +16,18 @@ package cache
 
 import (
 	"fmt"
+	"os"
+	"path/filepath"
+	"reflect"
+	"testing"
+	"time"
+
 	"github.com/lf-edge/ekuiper/internal/conf"
 	"github.com/lf-edge/ekuiper/internal/testx"
 	"github.com/lf-edge/ekuiper/internal/topo/context"
 	"github.com/lf-edge/ekuiper/internal/topo/node/metric"
 	"github.com/lf-edge/ekuiper/internal/topo/state"
 	"github.com/lf-edge/ekuiper/pkg/api"
-	"os"
-	"path/filepath"
-	"reflect"
-	"testing"
-	"time"
 )
 
 func TestPage(t *testing.T) {
@@ -207,7 +208,7 @@ func TestRun(t *testing.T) {
 		}()
 		exitCh := make(chan struct{})
 		// send data
-		sc := NewSyncCacheWithExitChanel(ctx, in, errCh, stats, tt.sconf, 100, exitCh)
+		_ = NewSyncCacheWithExitChanel(ctx, in, errCh, stats, tt.sconf, 100, exitCh)
 		for i := 0; i < tt.stopPt; i++ {
 			in <- tt.dataIn[i]
 			time.Sleep(1 * time.Millisecond)
@@ -218,7 +219,7 @@ func TestRun(t *testing.T) {
 
 		// send the second half data
 		ctx, cancel = context.WithValue(context.Background(), context.LoggerKey, contextLogger).WithMeta(fmt.Sprintf("rule%d", i), fmt.Sprintf("op%d", i), tempStore).WithCancel()
-		sc = NewSyncCache(ctx, in, errCh, stats, tt.sconf, 100)
+		sc := NewSyncCache(ctx, in, errCh, stats, tt.sconf, 100)
 		for i := tt.stopPt; i < len(tt.dataIn); i++ {
 			in <- tt.dataIn[i]
 			time.Sleep(1 * time.Millisecond)

+ 2 - 2
internal/topo/node/conf/sink.go

@@ -1,4 +1,4 @@
-// Copyright 2022 EMQ Technologies Co., Ltd.
+// Copyright 2022-2023 EMQ Technologies Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@ func GetSinkConf(sinkType string, action map[string]interface{}) map[string]inte
 		conf.Log.Warnf("fail to parse yaml for sink %s. Return error %v", sinkType, err)
 		return action
 	}
-	props := make(map[string]interface{})
+	var props map[string]interface{}
 	cfg := yamlOps.CopyConfContent()
 	if len(cfg) == 0 {
 		conf.Log.Warnf("fail to parse yaml for sink %s. Return an empty configuration", sinkType)

+ 10 - 6
internal/topo/node/window_op.go

@@ -1,4 +1,4 @@
-// Copyright 2021-2022 EMQ Technologies Co., Ltd.
+// Copyright 2021-2023 EMQ Technologies Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -17,7 +17,11 @@ package node
 import (
 	"encoding/gob"
 	"fmt"
+	"math"
+	"time"
+
 	"github.com/benbjohnson/clock"
+
 	"github.com/lf-edge/ekuiper/internal/conf"
 	"github.com/lf-edge/ekuiper/internal/topo/node/metric"
 	"github.com/lf-edge/ekuiper/internal/xsql"
@@ -25,8 +29,6 @@ import (
 	"github.com/lf-edge/ekuiper/pkg/ast"
 	"github.com/lf-edge/ekuiper/pkg/cast"
 	"github.com/lf-edge/ekuiper/pkg/infra"
-	"math"
-	"time"
 )
 
 type WindowConfig struct {
@@ -366,7 +368,8 @@ func (o *WindowOperator) execProcessingWindow(ctx api.StreamContext, inputs []*x
 				o.statManager.ProcessTimeStart()
 				log.Debugf("triggered by timeout")
 				inputs = o.scan(inputs, cast.TimeToUnixMilli(now), ctx)
-				//expire all inputs, so that when timer scan there is no item
+				_ = inputs
+				// expire all inputs, so that when timer scan there is no item
 				inputs = make([]*xsql.Tuple, 0)
 				o.statManager.ProcessTimeEnd()
 				ctx.PutState(WINDOW_INPUTS_KEY, inputs)
@@ -463,7 +466,7 @@ func (o *WindowOperator) scan(inputs []*xsql.Tuple, triggerTime int64, ctx api.S
 		windowEnd   = triggerTime
 	)
 	if o.window.Type == ast.HOPPING_WINDOW || o.window.Type == ast.SLIDING_WINDOW {
-		delta = o.calDelta(triggerTime, delta, log)
+		delta = o.calDelta(triggerTime, log)
 	}
 	results := &xsql.WindowTuples{
 		Content: make([]xsql.TupleRow, 0),
@@ -517,7 +520,8 @@ func (o *WindowOperator) scan(inputs []*xsql.Tuple, triggerTime int64, ctx api.S
 	return inputs[:i]
 }
 
-func (o *WindowOperator) calDelta(triggerTime int64, delta int64, log api.Logger) int64 {
+func (o *WindowOperator) calDelta(triggerTime int64, log api.Logger) int64 {
+	var delta int64
 	lastTriggerTime := o.triggerTime
 	if lastTriggerTime <= 0 {
 		delta = math.MaxInt16 //max int, all events for the initial window

+ 2 - 5
internal/xsql/func_invoker.go

@@ -1,4 +1,4 @@
-// Copyright 2021 EMQ Technologies Co., Ltd.
+// Copyright 2021-2023 EMQ Technologies Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@ package xsql
 
 import (
 	"fmt"
+
 	"github.com/lf-edge/ekuiper/internal/binder/function"
 	"github.com/lf-edge/ekuiper/pkg/api"
 	"github.com/lf-edge/ekuiper/pkg/ast"
@@ -43,10 +44,6 @@ func validateFuncs(funcName string, args []ast.Expr) error {
 }
 
 func ExecFunc(funcName string, f api.Function, args []interface{}, fctx api.FunctionContext) (interface{}, bool) {
-	var targs []interface{}
-	for _, arg := range args {
-		targs = append(targs, arg)
-	}
 	if mf, ok := f.(MultiFunc); ok {
 		return mf.ExecWithName(args, fctx, funcName)
 	} else {

+ 3 - 3
internal/xsql/parser.go

@@ -359,7 +359,7 @@ func (p *Parser) parseSorts() (ast.SortFields, error) {
 	if t, _ := p.scanIgnoreWhitespace(); t == ast.ORDER {
 		if t1, l1 := p.scanIgnoreWhitespace(); t1 == ast.BY {
 			for {
-				if t1, l1 = p.scanIgnoreWhitespace(); t1 == ast.IDENT {
+				if t1, _ = p.scanIgnoreWhitespace(); t1 == ast.IDENT {
 					s := ast.SortField{Ascending: true}
 
 					p.unscan()
@@ -471,9 +471,9 @@ func nameExpr(exp ast.Expr) string {
 }
 
 func (p *Parser) parseAlias() (string, error) {
-	tok, lit := p.scanIgnoreWhitespace()
+	tok, _ := p.scanIgnoreWhitespace()
 	if tok == ast.AS {
-		if tok, lit = p.scanIgnoreWhitespace(); tok != ast.IDENT {
+		if tok, lit := p.scanIgnoreWhitespace(); tok != ast.IDENT {
 			return "", fmt.Errorf("found %q, expected as alias.", lit)
 		} else {
 			return lit, nil

+ 4 - 8
internal/xsql/valuer.go

@@ -16,13 +16,14 @@ package xsql
 
 import (
 	"fmt"
-	"github.com/lf-edge/ekuiper/internal/binder/function"
-	"github.com/lf-edge/ekuiper/pkg/ast"
-	"github.com/lf-edge/ekuiper/pkg/cast"
 	"math"
 	"reflect"
 	"regexp"
 	"time"
+
+	"github.com/lf-edge/ekuiper/internal/binder/function"
+	"github.com/lf-edge/ekuiper/pkg/ast"
+	"github.com/lf-edge/ekuiper/pkg/cast"
 )
 
 var implicitValueFuncs = map[string]bool{
@@ -518,11 +519,6 @@ func (v *ValuerEval) evalBinaryExpr(expr *ast.BinaryExpr) interface{} {
 			return fmt.Errorf("LIKE operator left operand expects string, but found %v", lhs)
 		}
 		var result bool
-		switch rr := rhs.(type) {
-		case string:
-		case *regexp.Regexp: // literal
-			result = rr.MatchString(ls)
-		}
 		rs, ok := rhs.(*regexp.Regexp)
 		if !ok {
 			return fmt.Errorf("LIKE operator right operand expects string, but found %v", rhs)