From 16e67f12e45a577865c00fb375821722582ebaae Mon Sep 17 00:00:00 2001 From: Juanjo Alvarez Date: Tue, 23 Apr 2019 10:16:11 +0200 Subject: [PATCH 1/2] Fix some shadowed variables found by go vet Signed-off-by: Juanjo Alvarez --- auth/common_test.go | 31 ++++++++-------- mem/table.go | 2 +- mem/table_test.go | 40 ++++++++++----------- sql/analyzer/optimization_rules.go | 4 +-- sql/analyzer/prune_columns.go | 4 +-- sql/analyzer/pushdown.go | 16 ++++----- sql/catalog.go | 4 +-- sql/expression/comparison.go | 12 +++---- sql/expression/function/ceil_round_floor.go | 16 ++++----- sql/expression/function/concat.go | 4 +-- sql/expression/function/concat_ws.go | 4 +-- sql/expression/function/time_test.go | 4 +-- sql/expression/like.go | 12 +++---- sql/expression/unresolved.go | 4 +-- sql/index/pilosa/driver.go | 8 ++--- sql/index/pilosa/driver_test.go | 26 +++++++------- sql/index/pilosa/index.go | 12 +++---- sql/index/pilosa/lookup.go | 4 +-- sql/parse/lock.go | 4 +-- sql/parse/parse.go | 12 +++---- sql/parse/show_create.go | 18 +++++----- sql/plan/create_index.go | 4 +-- sql/plan/exchange_test.go | 1 - sql/plan/innerjoin.go | 10 +++--- sql/plan/limit_test.go | 22 ++++++------ sql/plan/resolved_table.go | 8 ++--- sql/plan/walk.go | 4 +-- 27 files changed, 145 insertions(+), 145 deletions(-) diff --git a/auth/common_test.go b/auth/common_test.go index 07b8e3462..df776bfd9 100644 --- a/auth/common_test.go +++ b/auth/common_test.go @@ -101,21 +101,21 @@ func testAuthentication( for _, c := range tests { t.Run(fmt.Sprintf("%s-%s", c.user, c.password), func(t *testing.T) { - req := require.New(t) + r := require.New(t) - db, err := dsql.Open("mysql", connString(c.user, c.password)) - req.NoError(err) - _, err = db.Query("SELECT 1") + db, e := dsql.Open("mysql", connString(c.user, c.password)) + r.NoError(e) + _, e = db.Query("SELECT 1") if c.success { - req.NoError(err) + r.NoError(e) } else { - req.Error(err) - req.Contains(err.Error(), "Access denied") + r.Error(e) + r.Contains(e.Error(), "Access denied") } - err = db.Close() - req.NoError(err) + e = db.Close() + r.NoError(e) if extra != nil { extra(t, c) @@ -196,20 +196,21 @@ func testAudit( for _, c := range tests { t.Run(c.user, func(t *testing.T) { - req := require.New(t) + r := require.New(t) - db, err := dsql.Open("mysql", connString(c.user, "")) - req.NoError(err) + var db *dsql.DB + db, err = dsql.Open("mysql", connString(c.user, "")) + r.NoError(err) _, err = db.Query(c.query) if c.success { - req.NoError(err) + r.NoError(err) } else { - req.Error(err) + r.Error(err) } err = db.Close() - req.NoError(err) + r.NoError(err) if extra != nil { extra(t, c) diff --git a/mem/table.go b/mem/table.go index bb9217732..fc92d0686 100644 --- a/mem/table.go +++ b/mem/table.go @@ -312,7 +312,7 @@ func (t *Table) HandledFilters(filters []sql.Expression) []sql.Expression { var handled []sql.Expression for _, f := range filters { var hasOtherFields bool - f.TransformUp(func(e sql.Expression) (sql.Expression, error) { + _, _ = f.TransformUp(func(e sql.Expression) (sql.Expression, error) { if e, ok := e.(*expression.GetField); ok { if e.Table() != t.name || !t.schema.Contains(e.Name(), t.name) { hasOtherFields = true diff --git a/mem/table_test.go b/mem/table_test.go index 98ae27ee8..f8413f784 100644 --- a/mem/table_test.go +++ b/mem/table_test.go @@ -151,24 +151,24 @@ var tests = []struct { }, indexColumns: []string{"col1", "col3"}, expectedKeyValues: []*indexKeyValue{ - &indexKeyValue{sql.NewRow("a", int64(100)), &indexValue{Key: "0", Pos: 0}}, - &indexKeyValue{sql.NewRow("c", int64(100)), &indexValue{Key: "0", Pos: 1}}, - &indexKeyValue{sql.NewRow("e", int64(200)), &indexValue{Key: "0", Pos: 2}}, - &indexKeyValue{sql.NewRow("b", int64(100)), &indexValue{Key: "1", Pos: 0}}, - &indexKeyValue{sql.NewRow("d", int64(200)), &indexValue{Key: "1", Pos: 1}}, - &indexKeyValue{sql.NewRow("f", int64(200)), &indexValue{Key: "1", Pos: 2}}, + {sql.NewRow("a", int64(100)), &indexValue{Key: "0", Pos: 0}}, + {sql.NewRow("c", int64(100)), &indexValue{Key: "0", Pos: 1}}, + {sql.NewRow("e", int64(200)), &indexValue{Key: "0", Pos: 2}}, + {sql.NewRow("b", int64(100)), &indexValue{Key: "1", Pos: 0}}, + {sql.NewRow("d", int64(200)), &indexValue{Key: "1", Pos: 1}}, + {sql.NewRow("f", int64(200)), &indexValue{Key: "1", Pos: 2}}, }, lookup: &dummyLookup{ values: map[string][]*indexValue{ - "0": []*indexValue{ - &indexValue{Key: "0", Pos: 0}, - &indexValue{Key: "0", Pos: 1}, - &indexValue{Key: "0", Pos: 2}, + "0": { + {Key: "0", Pos: 0}, + {Key: "0", Pos: 1}, + {Key: "0", Pos: 2}, }, - "1": []*indexValue{ - &indexValue{Key: "1", Pos: 0}, - &indexValue{Key: "1", Pos: 1}, - &indexValue{Key: "1", Pos: 2}, + "1": { + {Key: "1", Pos: 0}, + {Key: "1", Pos: 1}, + {Key: "1", Pos: 2}, }, }, }, @@ -194,14 +194,14 @@ func TestTable(t *testing.T) { require.NoError(err) for i := 0; i < test.numPartitions; i++ { - p, err := pIter.Next() - require.NoError(err) + p, e := pIter.Next() + require.NoError(e) - iter, err := table.PartitionRows(sql.NewEmptyContext(), p) - require.NoError(err) + iter, e := table.PartitionRows(sql.NewEmptyContext(), p) + require.NoError(e) - rows, err := sql.RowIterToRows(iter) - require.NoError(err) + rows, e := sql.RowIterToRows(iter) + require.NoError(e) expected := table.partitions[string(p.Key())] require.Len(rows, len(expected)) diff --git a/sql/analyzer/optimization_rules.go b/sql/analyzer/optimization_rules.go index f8795348b..01639f001 100644 --- a/sql/analyzer/optimization_rules.go +++ b/sql/analyzer/optimization_rules.go @@ -33,7 +33,7 @@ func optimizeDistinct(ctx *sql.Context, a *Analyzer, node sql.Node) (sql.Node, e defer span.Finish() a.Log("optimize distinct, node of type: %T", node) - if node, ok := node.(*plan.Distinct); ok { + if n, ok := node.(*plan.Distinct); ok { var isSorted bool _, _ = node.TransformUp(func(node sql.Node) (sql.Node, error) { a.Log("checking for optimization in node of type: %T", node) @@ -45,7 +45,7 @@ func optimizeDistinct(ctx *sql.Context, a *Analyzer, node sql.Node) (sql.Node, e if isSorted { a.Log("distinct optimized for ordered output") - return plan.NewOrderedDistinct(node.Child), nil + return plan.NewOrderedDistinct(n.Child), nil } } diff --git a/sql/analyzer/prune_columns.go b/sql/analyzer/prune_columns.go index 50711fb76..1bbc65932 100644 --- a/sql/analyzer/prune_columns.go +++ b/sql/analyzer/prune_columns.go @@ -17,12 +17,12 @@ func pruneColumns(ctx *sql.Context, a *Analyzer, n sql.Node) (sql.Node, error) { } if describe, ok := n.(*plan.DescribeQuery); ok { - n, err := pruneColumns(ctx, a, describe.Child) + pruned, err := pruneColumns(ctx, a, describe.Child) if err != nil { return nil, err } - return plan.NewDescribeQuery(describe.Format, n), nil + return plan.NewDescribeQuery(describe.Format, pruned), nil } columns := make(usedColumns) diff --git a/sql/analyzer/pushdown.go b/sql/analyzer/pushdown.go index 8c3bf5052..13db7f181 100644 --- a/sql/analyzer/pushdown.go +++ b/sql/analyzer/pushdown.go @@ -39,13 +39,13 @@ func pushdown(ctx *sql.Context, a *Analyzer, n sql.Node) (sql.Node, error) { // First step is to find all col exprs and group them by the table they mention. // Even if they appear multiple times, only the first one will be used. plan.InspectExpressions(n, func(e sql.Expression) bool { - if e, ok := e.(*expression.GetField); ok { - tf := tableField{e.Table(), e.Name()} + if gf, ok := e.(*expression.GetField); ok { + tf := tableField{gf.Table(), gf.Name()} if _, ok := tableFields[tf]; !ok { - a.Log("found used column %s.%s", e.Table(), e.Name()) + a.Log("found used column %s.%s", gf.Table(), gf.Name()) tableFields[tf] = struct{}{} - fieldsByTable[e.Table()] = append(fieldsByTable[e.Table()], e.Name()) - exprsByTable[e.Table()] = append(exprsByTable[e.Table()], e) + fieldsByTable[gf.Table()] = append(fieldsByTable[gf.Table()], gf.Name()) + exprsByTable[gf.Table()] = append(exprsByTable[gf.Table()], gf) } } return true @@ -59,14 +59,14 @@ func pushdown(ctx *sql.Context, a *Analyzer, n sql.Node) (sql.Node, error) { // then find all filters, also by table. Note that filters that mention // more than one table will not be passed to neither. - filters := make(filters) + filt := make(filters) plan.Inspect(n, func(node sql.Node) bool { a.Log("inspecting node of type: %T", node) switch node := node.(type) { case *plan.Filter: fs := exprToTableFilters(node.Expression) a.Log("found filters for %d tables %s", len(fs), node.Expression) - filters.merge(fs) + filt.merge(fs) } return true }) @@ -118,7 +118,7 @@ func pushdown(ctx *sql.Context, a *Analyzer, n sql.Node) (sql.Node, error) { var table = node.Table if ft, ok := table.(sql.FilteredTable); ok { - tableFilters := filters[node.Name()] + tableFilters := filt[node.Name()] handled := ft.HandledFilters(tableFilters) handledFilters = append(handledFilters, handled...) schema := node.Schema() diff --git a/sql/catalog.go b/sql/catalog.go index e6cf2160b..c2b35eeab 100644 --- a/sql/catalog.go +++ b/sql/catalog.go @@ -178,8 +178,8 @@ func (c *Catalog) UnlockTables(ctx *Context, id uint32) error { table, err := c.dbs.Table(db, t) if err == nil { if lockable, ok := table.(Lockable); ok { - if err := lockable.Unlock(ctx, id); err != nil { - errors = append(errors, err.Error()) + if e := lockable.Unlock(ctx, id); e != nil { + errors = append(errors, e.Error()) } } } else { diff --git a/sql/expression/comparison.go b/sql/expression/comparison.go index a3412dec9..dc8b90c5e 100644 --- a/sql/expression/comparison.go +++ b/sql/expression/comparison.go @@ -71,32 +71,32 @@ func (c *comparison) evalLeftAndRight(ctx *sql.Context, row sql.Row) (interface{ func (c *comparison) castLeftAndRight(left, right interface{}) (interface{}, interface{}, error) { if sql.IsNumber(c.Left().Type()) || sql.IsNumber(c.Right().Type()) { if sql.IsDecimal(c.Left().Type()) || sql.IsDecimal(c.Right().Type()) { - left, right, err := convertLeftAndRight(left, right, ConvertToDecimal) + l, r, err := convertLeftAndRight(left, right, ConvertToDecimal) if err != nil { return nil, nil, err } c.compareType = sql.Float64 - return left, right, nil + return l, r, nil } if sql.IsSigned(c.Left().Type()) || sql.IsSigned(c.Right().Type()) { - left, right, err := convertLeftAndRight(left, right, ConvertToSigned) + l, r, err := convertLeftAndRight(left, right, ConvertToSigned) if err != nil { return nil, nil, err } c.compareType = sql.Int64 - return left, right, nil + return l, r, nil } - left, right, err := convertLeftAndRight(left, right, ConvertToUnsigned) + l, r, err := convertLeftAndRight(left, right, ConvertToUnsigned) if err != nil { return nil, nil, err } c.compareType = sql.Uint64 - return left, right, nil + return l, r, nil } left, right, err := convertLeftAndRight(left, right, ConvertToChar) diff --git a/sql/expression/function/ceil_round_floor.go b/sql/expression/function/ceil_round_floor.go index 9e7ddc5ee..2afd1410a 100644 --- a/sql/expression/function/ceil_round_floor.go +++ b/sql/expression/function/ceil_round_floor.go @@ -189,9 +189,9 @@ func (r *Round) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { dVal := float64(0) if r.Right != nil { - dTemp, err := r.Right.Eval(ctx, row) - if err != nil { - return nil, err + dTemp, e := r.Right.Eval(ctx, row) + if e != nil { + return nil, e } if dTemp != nil { @@ -207,8 +207,8 @@ func (r *Round) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { case int: dVal = float64(dNum) default: - dTemp, err = sql.Float64.Convert(dTemp) - if err == nil { + dTemp, e = sql.Float64.Convert(dTemp) + if e == nil { dVal = dTemp.(float64) } } @@ -280,9 +280,9 @@ func (r *Round) TransformUp(f sql.TransformExprFunc) (sql.Expression, error) { args[1] = nil if r.Right != nil { - arg, err := r.Right.TransformUp(f) - if err != nil { - return nil, err + arg, e := r.Right.TransformUp(f) + if e != nil { + return nil, e } args[1] = arg } diff --git a/sql/expression/function/concat.go b/sql/expression/function/concat.go index 5777a030a..dc81f11d4 100644 --- a/sql/expression/function/concat.go +++ b/sql/expression/function/concat.go @@ -67,11 +67,11 @@ func (f *Concat) String() string { func (f *Concat) TransformUp(fn sql.TransformExprFunc) (sql.Expression, error) { var args = make([]sql.Expression, len(f.args)) for i, arg := range f.args { - arg, err := arg.TransformUp(fn) + a, err := arg.TransformUp(fn) if err != nil { return nil, err } - args[i] = arg + args[i] = a } expr, err := NewConcat(args...) diff --git a/sql/expression/function/concat_ws.go b/sql/expression/function/concat_ws.go index 4c856da1a..46b4dd24a 100644 --- a/sql/expression/function/concat_ws.go +++ b/sql/expression/function/concat_ws.go @@ -65,11 +65,11 @@ func (f *ConcatWithSeparator) String() string { func (f *ConcatWithSeparator) TransformUp(fn sql.TransformExprFunc) (sql.Expression, error) { var args = make([]sql.Expression, len(f.args)) for i, arg := range f.args { - arg, err := arg.TransformUp(fn) + a, err := arg.TransformUp(fn) if err != nil { return nil, err } - args[i] = arg + args[i] = a } expr, err := NewConcatWithSeparator(args...) diff --git a/sql/expression/function/time_test.go b/sql/expression/function/time_test.go index 71cdadd63..21491b31d 100644 --- a/sql/expression/function/time_test.go +++ b/sql/expression/function/time_test.go @@ -345,10 +345,10 @@ func TestCalcWeek(t *testing.T) { func TestNow(t *testing.T) { require := require.New(t) date := time.Date(2018, time.December, 2, 16, 25, 0, 0, time.Local) - clock := clock(func() time.Time { + cl := clock(func() time.Time { return date }) - f := &Now{clock} + f := &Now{cl} result, err := f.Eval(nil, nil) require.NoError(err) diff --git a/sql/expression/like.go b/sql/expression/like.go index bd9c45b2b..7086bb07a 100644 --- a/sql/expression/like.go +++ b/sql/expression/like.go @@ -59,13 +59,13 @@ func (l *Like) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { ) // eval right and convert to text if !l.cached || l.pool == nil { - v, err := l.Right.Eval(ctx, row) - if err != nil || v == nil { - return nil, err + v, e := l.Right.Eval(ctx, row) + if e != nil || v == nil { + return nil, e } - v, err = sql.Text.Convert(v) - if err != nil { - return nil, err + v, e = sql.Text.Convert(v) + if e != nil { + return nil, e } right = patternToRegex(v.(string)) } diff --git a/sql/expression/unresolved.go b/sql/expression/unresolved.go index 4587edd48..537ed0973 100644 --- a/sql/expression/unresolved.go +++ b/sql/expression/unresolved.go @@ -130,11 +130,11 @@ func (*UnresolvedFunction) Eval(ctx *sql.Context, r sql.Row) (interface{}, error func (uf *UnresolvedFunction) TransformUp(f sql.TransformExprFunc) (sql.Expression, error) { var rc []sql.Expression for _, c := range uf.Arguments { - c, err := c.TransformUp(f) + ct, err := c.TransformUp(f) if err != nil { return nil, err } - rc = append(rc, c) + rc = append(rc, ct) } return f(NewUnresolvedFunction(uf.name, uf.IsAggregate, rc...)) diff --git a/sql/index/pilosa/driver.go b/sql/index/pilosa/driver.go index 4df86a5a7..dd9bba207 100644 --- a/sql/index/pilosa/driver.go +++ b/sql/index/pilosa/driver.go @@ -184,7 +184,7 @@ func (d *Driver) loadIndex(db, table, id string) (*pilosaIndex, error) { dir := filepath.Join(d.root, db, table, id) config := d.configFilePath(db, table, id) - if _, err := os.Stat(config); err != nil { + if _, err = os.Stat(config); err != nil { return nil, errCorruptedIndex.New(dir) } @@ -202,7 +202,7 @@ func (d *Driver) loadIndex(db, table, id string) (*pilosaIndex, error) { "dir": dir, }) log.Warn("could not read index file, index is corrupt and will be deleted") - if err := os.RemoveAll(dir); err != nil { + if e := os.RemoveAll(dir); e != nil { log.Warn("unable to remove corrupted index: " + dir) } @@ -262,8 +262,8 @@ func (d *Driver) savePartition( if !ok { return 0, errMappingNotFound.New(mk) } - if err := mapping.openCreate(true); err != nil { - return 0, err + if e := mapping.openCreate(true); e != nil { + return 0, e } defer func() { diff --git a/sql/index/pilosa/driver_test.go b/sql/index/pilosa/driver_test.go index d66065a7c..aac7d377d 100644 --- a/sql/index/pilosa/driver_test.go +++ b/sql/index/pilosa/driver_test.go @@ -192,18 +192,18 @@ func TestSaveAndLoad(t *testing.T) { for partition, records := range it.records { for _, r := range records { - lookup, err := sqlIdx.Get(r.values...) - require.NoError(err) + lookup, e := sqlIdx.Get(r.values...) + require.NoError(e) - lit, err := lookup.Values(testPartition(partition)) - require.NoError(err) + lit, e := lookup.Values(testPartition(partition)) + require.NoError(e) for { - loc, err := lit.Next() - if err == io.EOF { + loc, e := lit.Next() + if e == io.EOF { break } - require.NoError(err) + require.NoError(e) locations[partition] = append(locations[partition], string(loc)) } @@ -869,8 +869,8 @@ func TestUnionDiffAsc(t *testing.T) { for partition, records := range it.records { ls[partition] = make([]*indexLookup, it.total) for i, r := range records { - l, err := pilosaIdx.Get(r.values...) - require.NoError(err) + l, e := pilosaIdx.Get(r.values...) + require.NoError(e) ls[partition][i], _ = l.(*indexLookup) } } @@ -882,8 +882,8 @@ func TestUnionDiffAsc(t *testing.T) { require.NoError(err) for i := 1; i < it.total-1; i += 2 { - loc, err := diffIt.Next() - require.NoError(err) + loc, e := diffIt.Next() + require.NoError(e) require.Equal(it.records[0][i].location, loc) } @@ -936,8 +936,8 @@ func TestInterRanges(t *testing.T) { require.NoError(err) for i := ranges[0]; i < ranges[1]; i++ { - loc, err := interIt.Next() - require.NoError(err) + loc, e := interIt.Next() + require.NoError(e) require.Equal(it.records[0][i].location, loc) } diff --git a/sql/index/pilosa/index.go b/sql/index/pilosa/index.go index 38d741055..5439068ae 100644 --- a/sql/index/pilosa/index.go +++ b/sql/index/pilosa/index.go @@ -303,9 +303,9 @@ func newAscendLookup(f *filteredLookup, gte []interface{}, lt []interface{}) *as return false, err } - cmp, err := compare(v, l.gte[i]) - if err != nil { - return false, err + cmp, e := compare(v, l.gte[i]) + if e != nil { + return false, e } if cmp < 0 { @@ -349,9 +349,9 @@ func newDescendLookup(f *filteredLookup, gt []interface{}, lte []interface{}) *d return false, err } - cmp, err := compare(v, l.gt[i]) - if err != nil { - return false, err + cmp, e := compare(v, l.gt[i]) + if e != nil { + return false, e } if cmp <= 0 { diff --git a/sql/index/pilosa/lookup.go b/sql/index/pilosa/lookup.go index de3878b14..9cb85704d 100644 --- a/sql/index/pilosa/lookup.go +++ b/sql/index/pilosa/lookup.go @@ -350,8 +350,8 @@ func (l *filteredLookup) Values(p sql.Partition) (sql.IndexValueIter, error) { } bits := row.Columns() - if err := m.open(); err != nil { - return nil, err + if e := m.open(); e != nil { + return nil, e } defer m.close() diff --git a/sql/parse/lock.go b/sql/parse/lock.go index 6560253ad..df3dd7f27 100644 --- a/sql/parse/lock.go +++ b/sql/parse/lock.go @@ -39,8 +39,8 @@ func readTableLocks(tables *[]*plan.TableLock) parseFunc { *tables = append(*tables, t) - if err := skipSpaces(rd); err != nil { - return err + if e := skipSpaces(rd); e != nil { + return e } b, err := rd.Peek(1) diff --git a/sql/parse/parse.go b/sql/parse/parse.go index a222be31c..f5be18a2a 100644 --- a/sql/parse/parse.go +++ b/sql/parse/parse.go @@ -1043,14 +1043,14 @@ func caseExprToExpression(e *sqlparser.CaseExpr) (sql.Expression, error) { var branches []expression.CaseBranch for _, w := range e.Whens { - cond, err := exprToExpression(w.Cond) - if err != nil { - return nil, err + cond, e := exprToExpression(w.Cond) + if e != nil { + return nil, e } - val, err := exprToExpression(w.Val) - if err != nil { - return nil, err + val, e := exprToExpression(w.Val) + if e != nil { + return nil, e } branches = append(branches, expression.CaseBranch{ diff --git a/sql/parse/show_create.go b/sql/parse/show_create.go index 2ef5989b5..0fee98ec1 100644 --- a/sql/parse/show_create.go +++ b/sql/parse/show_create.go @@ -42,8 +42,8 @@ func parseShowCreate(s string) (sql.Node, error) { } else if err == nil && ru == '.' { db = table - if err := readQuotableIdent(&table)(r); err != nil { - return nil, err + if e := readQuotableIdent(&table)(r); e != nil { + return nil, e } } @@ -71,17 +71,17 @@ func parseShowCreate(s string) (sql.Node, error) { // If ` is the next character, it's a db name. Otherwise it may be // a table name or IF NOT EXISTS. if nextByte[0] == '`' { - if err := readQuotableIdent(&next)(r); err != nil { - return nil, err + if e := readQuotableIdent(&next)(r); e != nil { + return nil, e } } else { - if err := readIdent(&next)(r); err != nil { - return nil, err + if e := readIdent(&next)(r); e != nil { + return nil, e } if next == "if" { ifNotExists = true - err := parseFuncs{ + e := parseFuncs{ skipSpaces, expect("not"), skipSpaces, @@ -89,8 +89,8 @@ func parseShowCreate(s string) (sql.Node, error) { skipSpaces, readQuotableIdent(&next), }.exec(r) - if err != nil { - return nil, err + if e != nil { + return nil, e } } } diff --git a/sql/plan/create_index.go b/sql/plan/create_index.go index f8553e36a..b1d7a969e 100644 --- a/sql/plan/create_index.go +++ b/sql/plan/create_index.go @@ -330,8 +330,8 @@ func getColumnsAndPrepareExpressions( } var idx int - if i, ok := seen[gf.Name()]; ok { - idx = i + if j, ok := seen[gf.Name()]; ok { + idx = j } else { idx = len(columns) columns = append(columns, gf.Name()) diff --git a/sql/plan/exchange_test.go b/sql/plan/exchange_test.go index 486ebb21a..55c51d295 100644 --- a/sql/plan/exchange_test.go +++ b/sql/plan/exchange_test.go @@ -183,7 +183,6 @@ type partitionPanic struct { func (*partitionPanic) Next() (sql.Partition, error) { panic("partitionPanic.Next") - return nil, nil } func (p *partitionPanic) Close() error { diff --git a/sql/plan/innerjoin.go b/sql/plan/innerjoin.go index aa55c2a35..8217b5544 100644 --- a/sql/plan/innerjoin.go +++ b/sql/plan/innerjoin.go @@ -270,8 +270,8 @@ func (i *innerJoinIter) fitsInMemory() bool { func (i *innerJoinIter) loadRight() (row sql.Row, skip bool, err error) { if i.mode == memoryMode { if len(i.right) == 0 { - if err := i.loadRightInMemory(); err != nil { - return nil, false, err + if e := i.loadRightInMemory(); e != nil { + return nil, false, e } } @@ -287,9 +287,9 @@ func (i *innerJoinIter) loadRight() (row sql.Row, skip bool, err error) { } if i.r == nil { - iter, err := i.rp.RowIter(i.ctx) - if err != nil { - return nil, false, err + iter, e := i.rp.RowIter(i.ctx) + if e != nil { + return nil, false, e } i.r = iter diff --git a/sql/plan/limit_test.go b/sql/plan/limit_test.go index c5a682196..6f77885bb 100644 --- a/sql/plan/limit_test.go +++ b/sql/plan/limit_test.go @@ -38,31 +38,31 @@ func TestLimitImplementsNode(t *testing.T) { } func TestLimit0(t *testing.T) { - _, testingTableSize := getTestingTable(t) + _, size := getTestingTable(t) testingLimit := 0 iterator, _ := getLimitedIterator(t, int64(testingLimit)) - testLimitOverflow(t, iterator, testingLimit, testingTableSize) + testLimitOverflow(t, iterator, testingLimit, size) } func TestLimitLessThanTotal(t *testing.T) { - _, testingTableSize := getTestingTable(t) - testingLimit := testingTableSize - 1 + _, size := getTestingTable(t) + testingLimit := size - 1 iterator, _ := getLimitedIterator(t, int64(testingLimit)) - testLimitOverflow(t, iterator, testingLimit, testingTableSize) + testLimitOverflow(t, iterator, testingLimit, size) } func TestLimitEqualThanTotal(t *testing.T) { - _, testingTableSize := getTestingTable(t) - testingLimit := testingTableSize + _, size := getTestingTable(t) + testingLimit := size iterator, _ := getLimitedIterator(t, int64(testingLimit)) - testLimitOverflow(t, iterator, testingLimit, testingTableSize) + testLimitOverflow(t, iterator, testingLimit, size) } func TestLimitGreaterThanTotal(t *testing.T) { - _, testingTableSize := getTestingTable(t) - testingLimit := testingTableSize + 1 + _, size := getTestingTable(t) + testingLimit := size + 1 iterator, _ := getLimitedIterator(t, int64(testingLimit)) - testLimitOverflow(t, iterator, testingLimit, testingTableSize) + testLimitOverflow(t, iterator, testingLimit, size) } func testLimitOverflow(t *testing.T, iter sql.RowIter, limit int, dataSize int) { diff --git a/sql/plan/resolved_table.go b/sql/plan/resolved_table.go index d031db8b0..5d10a5780 100644 --- a/sql/plan/resolved_table.go +++ b/sql/plan/resolved_table.go @@ -73,8 +73,8 @@ func (i *tableIter) Next() (sql.Row, error) { partition, err := i.partitions.Next() if err != nil { if err == io.EOF { - if err := i.partitions.Close(); err != nil { - return nil, err + if e := i.partitions.Close(); e != nil { + return nil, e } } @@ -95,8 +95,8 @@ func (i *tableIter) Next() (sql.Row, error) { row, err := i.rows.Next() if err != nil && err == io.EOF { - if err := i.rows.Close(); err != nil { - return nil, err + if e := i.rows.Close(); e != nil { + return nil, e } i.partition = nil diff --git a/sql/plan/walk.go b/sql/plan/walk.go index 3a940a0b4..25285d4a1 100644 --- a/sql/plan/walk.go +++ b/sql/plan/walk.go @@ -52,8 +52,8 @@ func Inspect(node sql.Node, f func(sql.Node) bool) { // expression it finds. func WalkExpressions(v expression.Visitor, node sql.Node) { Inspect(node, func(node sql.Node) bool { - if node, ok := node.(sql.Expressioner); ok { - for _, e := range node.Expressions() { + if n, ok := node.(sql.Expressioner); ok { + for _, e := range n.Expressions() { expression.Walk(v, e) } } From 04aa0ac9d6803b84f657f4e4dde07df0e7da3400 Mon Sep 17 00:00:00 2001 From: Juanjo Alvarez Date: Wed, 24 Apr 2019 14:01:56 +0200 Subject: [PATCH 2/2] Dont rename err to e except when needed Signed-off-by: Juanjo Alvarez --- auth/common_test.go | 17 +++++------ mem/table_test.go | 15 ++++++---- sql/expression/function/ceil_round_floor.go | 18 ++++++------ sql/expression/function/time_test.go | 4 +-- sql/expression/like.go | 13 +++++---- sql/index/pilosa/driver.go | 9 +++--- sql/index/pilosa/driver_test.go | 32 ++++++++++++--------- sql/index/pilosa/index.go | 14 +++++---- sql/index/pilosa/lookup.go | 7 +++-- sql/parse/lock.go | 7 +++-- sql/parse/parse.go | 14 +++++---- sql/parse/show_create.go | 18 ++++++------ sql/plan/innerjoin.go | 13 +++++---- sql/plan/resolved_table.go | 4 +-- sql/plan/walk.go | 4 +-- 15 files changed, 105 insertions(+), 84 deletions(-) diff --git a/auth/common_test.go b/auth/common_test.go index df776bfd9..d9e784cd9 100644 --- a/auth/common_test.go +++ b/auth/common_test.go @@ -103,19 +103,20 @@ func testAuthentication( t.Run(fmt.Sprintf("%s-%s", c.user, c.password), func(t *testing.T) { r := require.New(t) - db, e := dsql.Open("mysql", connString(c.user, c.password)) - r.NoError(e) - _, e = db.Query("SELECT 1") + var db *dsql.DB + db, err = dsql.Open("mysql", connString(c.user, c.password)) + r.NoError(err) + _, err = db.Query("SELECT 1") if c.success { - r.NoError(e) + r.NoError(err) } else { - r.Error(e) - r.Contains(e.Error(), "Access denied") + r.Error(err) + r.Contains(err.Error(), "Access denied") } - e = db.Close() - r.NoError(e) + err = db.Close() + r.NoError(err) if extra != nil { extra(t, c) diff --git a/mem/table_test.go b/mem/table_test.go index f8413f784..9871a68e3 100644 --- a/mem/table_test.go +++ b/mem/table_test.go @@ -194,14 +194,17 @@ func TestTable(t *testing.T) { require.NoError(err) for i := 0; i < test.numPartitions; i++ { - p, e := pIter.Next() - require.NoError(e) + var p sql.Partition + p, err = pIter.Next() + require.NoError(err) - iter, e := table.PartitionRows(sql.NewEmptyContext(), p) - require.NoError(e) + var iter sql.RowIter + iter, err = table.PartitionRows(sql.NewEmptyContext(), p) + require.NoError(err) - rows, e := sql.RowIterToRows(iter) - require.NoError(e) + var rows []sql.Row + rows, err = sql.RowIterToRows(iter) + require.NoError(err) expected := table.partitions[string(p.Key())] require.Len(rows, len(expected)) diff --git a/sql/expression/function/ceil_round_floor.go b/sql/expression/function/ceil_round_floor.go index 2afd1410a..1c91197c2 100644 --- a/sql/expression/function/ceil_round_floor.go +++ b/sql/expression/function/ceil_round_floor.go @@ -189,9 +189,10 @@ func (r *Round) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { dVal := float64(0) if r.Right != nil { - dTemp, e := r.Right.Eval(ctx, row) - if e != nil { - return nil, e + var dTemp interface{} + dTemp, err = r.Right.Eval(ctx, row) + if err != nil { + return nil, err } if dTemp != nil { @@ -207,8 +208,8 @@ func (r *Round) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { case int: dVal = float64(dNum) default: - dTemp, e = sql.Float64.Convert(dTemp) - if e == nil { + dTemp, err = sql.Float64.Convert(dTemp) + if err == nil { dVal = dTemp.(float64) } } @@ -280,9 +281,10 @@ func (r *Round) TransformUp(f sql.TransformExprFunc) (sql.Expression, error) { args[1] = nil if r.Right != nil { - arg, e := r.Right.TransformUp(f) - if e != nil { - return nil, e + var arg sql.Expression + arg, err = r.Right.TransformUp(f) + if err != nil { + return nil, err } args[1] = arg } diff --git a/sql/expression/function/time_test.go b/sql/expression/function/time_test.go index 21491b31d..867e2e86b 100644 --- a/sql/expression/function/time_test.go +++ b/sql/expression/function/time_test.go @@ -345,10 +345,10 @@ func TestCalcWeek(t *testing.T) { func TestNow(t *testing.T) { require := require.New(t) date := time.Date(2018, time.December, 2, 16, 25, 0, 0, time.Local) - cl := clock(func() time.Time { + clk := clock(func() time.Time { return date }) - f := &Now{cl} + f := &Now{clk} result, err := f.Eval(nil, nil) require.NoError(err) diff --git a/sql/expression/like.go b/sql/expression/like.go index 7086bb07a..4049b4dfb 100644 --- a/sql/expression/like.go +++ b/sql/expression/like.go @@ -59,13 +59,14 @@ func (l *Like) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) { ) // eval right and convert to text if !l.cached || l.pool == nil { - v, e := l.Right.Eval(ctx, row) - if e != nil || v == nil { - return nil, e + var v interface{} + v, err = l.Right.Eval(ctx, row) + if err != nil || v == nil { + return nil, err } - v, e = sql.Text.Convert(v) - if e != nil { - return nil, e + v, err = sql.Text.Convert(v) + if err != nil { + return nil, err } right = patternToRegex(v.(string)) } diff --git a/sql/index/pilosa/driver.go b/sql/index/pilosa/driver.go index dd9bba207..6a0a4ada1 100644 --- a/sql/index/pilosa/driver.go +++ b/sql/index/pilosa/driver.go @@ -202,7 +202,7 @@ func (d *Driver) loadIndex(db, table, id string) (*pilosaIndex, error) { "dir": dir, }) log.Warn("could not read index file, index is corrupt and will be deleted") - if e := os.RemoveAll(dir); e != nil { + if err = os.RemoveAll(dir); err != nil { log.Warn("unable to remove corrupted index: " + dir) } @@ -262,8 +262,8 @@ func (d *Driver) savePartition( if !ok { return 0, errMappingNotFound.New(mk) } - if e := mapping.openCreate(true); e != nil { - return 0, e + if err := mapping.openCreate(true); err != nil { + return 0, err } defer func() { @@ -304,7 +304,8 @@ func (d *Driver) savePartition( continue } - rowID, err := mapping.getRowID(field.Name(), values[i]) + var rowID uint64 + rowID, err = mapping.getRowID(field.Name(), values[i]) if err != nil { return 0, err } diff --git a/sql/index/pilosa/driver_test.go b/sql/index/pilosa/driver_test.go index aac7d377d..752de6a49 100644 --- a/sql/index/pilosa/driver_test.go +++ b/sql/index/pilosa/driver_test.go @@ -192,18 +192,21 @@ func TestSaveAndLoad(t *testing.T) { for partition, records := range it.records { for _, r := range records { - lookup, e := sqlIdx.Get(r.values...) - require.NoError(e) + var lookup sql.IndexLookup + lookup, err = sqlIdx.Get(r.values...) + require.NoError(err) - lit, e := lookup.Values(testPartition(partition)) - require.NoError(e) + var lit sql.IndexValueIter + lit, err = lookup.Values(testPartition(partition)) + require.NoError(err) for { - loc, e := lit.Next() - if e == io.EOF { + var loc []byte + loc, err = lit.Next() + if err == io.EOF { break } - require.NoError(e) + require.NoError(err) locations[partition] = append(locations[partition], string(loc)) } @@ -869,8 +872,9 @@ func TestUnionDiffAsc(t *testing.T) { for partition, records := range it.records { ls[partition] = make([]*indexLookup, it.total) for i, r := range records { - l, e := pilosaIdx.Get(r.values...) - require.NoError(e) + var l sql.IndexLookup + l, err = pilosaIdx.Get(r.values...) + require.NoError(err) ls[partition][i], _ = l.(*indexLookup) } } @@ -882,8 +886,9 @@ func TestUnionDiffAsc(t *testing.T) { require.NoError(err) for i := 1; i < it.total-1; i += 2 { - loc, e := diffIt.Next() - require.NoError(e) + var loc []byte + loc, err = diffIt.Next() + require.NoError(err) require.Equal(it.records[0][i].location, loc) } @@ -936,8 +941,9 @@ func TestInterRanges(t *testing.T) { require.NoError(err) for i := ranges[0]; i < ranges[1]; i++ { - loc, e := interIt.Next() - require.NoError(e) + var loc []byte + loc, err = interIt.Next() + require.NoError(err) require.Equal(it.records[0][i].location, loc) } diff --git a/sql/index/pilosa/index.go b/sql/index/pilosa/index.go index 5439068ae..55e898202 100644 --- a/sql/index/pilosa/index.go +++ b/sql/index/pilosa/index.go @@ -303,9 +303,10 @@ func newAscendLookup(f *filteredLookup, gte []interface{}, lt []interface{}) *as return false, err } - cmp, e := compare(v, l.gte[i]) - if e != nil { - return false, e + var cmp int + cmp, err = compare(v, l.gte[i]) + if err != nil { + return false, err } if cmp < 0 { @@ -349,9 +350,10 @@ func newDescendLookup(f *filteredLookup, gt []interface{}, lte []interface{}) *d return false, err } - cmp, e := compare(v, l.gt[i]) - if e != nil { - return false, e + var cmp int + cmp, err = compare(v, l.gt[i]) + if err != nil { + return false, err } if cmp <= 0 { diff --git a/sql/index/pilosa/lookup.go b/sql/index/pilosa/lookup.go index 9cb85704d..27a8cef81 100644 --- a/sql/index/pilosa/lookup.go +++ b/sql/index/pilosa/lookup.go @@ -350,8 +350,8 @@ func (l *filteredLookup) Values(p sql.Partition) (sql.IndexValueIter, error) { } bits := row.Columns() - if e := m.open(); e != nil { - return nil, e + if err = m.open(); err != nil { + return nil, err } defer m.close() @@ -455,7 +455,8 @@ func (l *negateLookup) intersectExpressions(p sql.Partition, m *mapping) (*pilos var r *pilosa.Row // rowIDs start with 1 for ri := uint64(1); ri <= maxRowID; ri++ { - rr, err := field.Row(ri) + var rr *pilosa.Row + rr, err = field.Row(ri) if err != nil { return nil, err } diff --git a/sql/parse/lock.go b/sql/parse/lock.go index df3dd7f27..065c56cd0 100644 --- a/sql/parse/lock.go +++ b/sql/parse/lock.go @@ -39,11 +39,12 @@ func readTableLocks(tables *[]*plan.TableLock) parseFunc { *tables = append(*tables, t) - if e := skipSpaces(rd); e != nil { - return e + if err = skipSpaces(rd); err != nil { + return err } - b, err := rd.Peek(1) + var b []byte + b, err = rd.Peek(1) if err == io.EOF { return nil } else if err != nil { diff --git a/sql/parse/parse.go b/sql/parse/parse.go index f5be18a2a..a476757ae 100644 --- a/sql/parse/parse.go +++ b/sql/parse/parse.go @@ -1043,14 +1043,16 @@ func caseExprToExpression(e *sqlparser.CaseExpr) (sql.Expression, error) { var branches []expression.CaseBranch for _, w := range e.Whens { - cond, e := exprToExpression(w.Cond) - if e != nil { - return nil, e + var cond sql.Expression + cond, err = exprToExpression(w.Cond) + if err != nil { + return nil, err } - val, e := exprToExpression(w.Val) - if e != nil { - return nil, e + var val sql.Expression + val, err = exprToExpression(w.Val) + if err != nil { + return nil, err } branches = append(branches, expression.CaseBranch{ diff --git a/sql/parse/show_create.go b/sql/parse/show_create.go index 0fee98ec1..09bb7d3ff 100644 --- a/sql/parse/show_create.go +++ b/sql/parse/show_create.go @@ -42,8 +42,8 @@ func parseShowCreate(s string) (sql.Node, error) { } else if err == nil && ru == '.' { db = table - if e := readQuotableIdent(&table)(r); e != nil { - return nil, e + if err = readQuotableIdent(&table)(r); err != nil { + return nil, err } } @@ -71,17 +71,17 @@ func parseShowCreate(s string) (sql.Node, error) { // If ` is the next character, it's a db name. Otherwise it may be // a table name or IF NOT EXISTS. if nextByte[0] == '`' { - if e := readQuotableIdent(&next)(r); e != nil { - return nil, e + if err = readQuotableIdent(&next)(r); err != nil { + return nil, err } } else { - if e := readIdent(&next)(r); e != nil { - return nil, e + if err = readIdent(&next)(r); err != nil { + return nil, err } if next == "if" { ifNotExists = true - e := parseFuncs{ + err = parseFuncs{ skipSpaces, expect("not"), skipSpaces, @@ -89,8 +89,8 @@ func parseShowCreate(s string) (sql.Node, error) { skipSpaces, readQuotableIdent(&next), }.exec(r) - if e != nil { - return nil, e + if err != nil { + return nil, err } } } diff --git a/sql/plan/innerjoin.go b/sql/plan/innerjoin.go index 8217b5544..50297b0bd 100644 --- a/sql/plan/innerjoin.go +++ b/sql/plan/innerjoin.go @@ -8,7 +8,7 @@ import ( "strconv" "strings" - opentracing "github.com/opentracing/opentracing-go" + "github.com/opentracing/opentracing-go" "github.com/pbnjay/memory" "github.com/sirupsen/logrus" "gopkg.in/src-d/go-mysql-server.v0/sql" @@ -270,8 +270,8 @@ func (i *innerJoinIter) fitsInMemory() bool { func (i *innerJoinIter) loadRight() (row sql.Row, skip bool, err error) { if i.mode == memoryMode { if len(i.right) == 0 { - if e := i.loadRightInMemory(); e != nil { - return nil, false, e + if err = i.loadRightInMemory(); err != nil { + return nil, false, err } } @@ -287,9 +287,10 @@ func (i *innerJoinIter) loadRight() (row sql.Row, skip bool, err error) { } if i.r == nil { - iter, e := i.rp.RowIter(i.ctx) - if e != nil { - return nil, false, e + var iter sql.RowIter + iter, err = i.rp.RowIter(i.ctx) + if err != nil { + return nil, false, err } i.r = iter diff --git a/sql/plan/resolved_table.go b/sql/plan/resolved_table.go index 5d10a5780..bf3e102bb 100644 --- a/sql/plan/resolved_table.go +++ b/sql/plan/resolved_table.go @@ -95,8 +95,8 @@ func (i *tableIter) Next() (sql.Row, error) { row, err := i.rows.Next() if err != nil && err == io.EOF { - if e := i.rows.Close(); e != nil { - return nil, e + if err = i.rows.Close(); err != nil { + return nil, err } i.partition = nil diff --git a/sql/plan/walk.go b/sql/plan/walk.go index 25285d4a1..f76ae145a 100644 --- a/sql/plan/walk.go +++ b/sql/plan/walk.go @@ -53,8 +53,8 @@ func Inspect(node sql.Node, f func(sql.Node) bool) { func WalkExpressions(v expression.Visitor, node sql.Node) { Inspect(node, func(node sql.Node) bool { if n, ok := node.(sql.Expressioner); ok { - for _, e := range n.Expressions() { - expression.Walk(v, e) + for _, err := range n.Expressions() { + expression.Walk(v, err) } } return true