Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

Commit

Permalink
Fix some shadowed variables found by go vet
Browse files Browse the repository at this point in the history
Signed-off-by: Juanjo Alvarez <juanjo@sourced.tech>
  • Loading branch information
Juanjo Alvarez committed Apr 23, 2019
1 parent 09df997 commit d2841ca
Show file tree
Hide file tree
Showing 26 changed files with 132 additions and 132 deletions.
34 changes: 17 additions & 17 deletions auth/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -196,20 +196,20 @@ 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)
_, err = db.Query(c.query)
db, e := dsql.Open("mysql", connString(c.user, ""))
r.NoError(e)
_, e = db.Query(c.query)

if c.success {
req.NoError(err)
r.NoError(e)
} else {
req.Error(err)
r.Error(e)
}

err = db.Close()
req.NoError(err)
e = db.Close()
r.NoError(e)

if extra != nil {
extra(t, c)
Expand Down
2 changes: 1 addition & 1 deletion mem/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions mem/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions sql/analyzer/optimization_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
}

Expand Down
4 changes: 2 additions & 2 deletions sql/analyzer/prune_columns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions sql/analyzer/pushdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
})
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions sql/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions sql/expression/comparison.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions sql/expression/function/ceil_round_floor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions sql/expression/function/concat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
4 changes: 2 additions & 2 deletions sql/expression/function/concat_ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
4 changes: 2 additions & 2 deletions sql/expression/function/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions sql/expression/like.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
4 changes: 2 additions & 2 deletions sql/expression/unresolved.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...))
Expand Down
8 changes: 4 additions & 4 deletions sql/index/pilosa/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand Down Expand Up @@ -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() {
Expand Down
Loading

0 comments on commit d2841ca

Please sign in to comment.