Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update golangci-lint config and fix related issues #27

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,961 changes: 1,746 additions & 215 deletions .golangci.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cmd/shell/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func main() {
sqlParser := engine.ParseFn(func(sql string) (ast.Node, error) {
lx := lexer.New(sql)
pr := parser.New(lx)

return pr.Parse()
})

Expand Down
2 changes: 2 additions & 0 deletions internal/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,13 @@ Commands:
\help Show help
\quit Quit
`

return help
}

func (s *Shell) quit() string {
close(s.closeCh)

return "Bye!\n"
}

Expand Down
8 changes: 4 additions & 4 deletions internal/sql/engine/engine_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package engine_test

import (
"fmt"
"errors"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -103,7 +103,7 @@ func TestEngine_Query(t *testing.T) {

input := "select true"
database := "playground"
expectedErr := fmt.Errorf("something went wrong")
expectedErr := errors.New("something went wrong")

parser := NewMockParser(ctrl)
planner := NewMockPlanner(ctrl)
Expand All @@ -125,7 +125,7 @@ func TestEngine_Query(t *testing.T) {

input := "select true"
database := "playground"
expectedErr := fmt.Errorf("something went wrong")
expectedErr := errors.New("something went wrong")
astNode := &ast.SelectStatement{
Result: []ast.ResultStatement{
{
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestEngine_Query(t *testing.T) {

input := "select true"
database := "playground"
expectedErr := fmt.Errorf("something went wrong")
expectedErr := errors.New("something went wrong")
astNode := &ast.SelectStatement{
Result: []ast.ResultStatement{
{
Expand Down
5 changes: 3 additions & 2 deletions internal/sql/expr/binary_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package expr_test

import (
"errors"
"fmt"
"testing"

Expand Down Expand Up @@ -909,7 +910,7 @@ func TestBinary_Eval(t *testing.T) {
Right: rightNode,
}

expected := fmt.Errorf("unexpected error")
expected := errors.New("unexpected error")
leftNode.EXPECT().Eval(nil).Return(nil, expected)

value, err := equal.Eval(nil)
Expand All @@ -932,7 +933,7 @@ func TestBinary_Eval(t *testing.T) {
Right: rightNode,
}

expected := fmt.Errorf("unexpected error")
expected := errors.New("unexpected error")
leftValue := sql.NewMockValue(ctrl)

gomock.InOrder(
Expand Down
3 changes: 2 additions & 1 deletion internal/sql/expr/column.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package expr

import (
"errors"
"fmt"

"github.com/i-sevostyanov/NanoDB/internal/sql"
Expand All @@ -17,7 +18,7 @@ func (c Column) String() string {

func (c Column) Eval(row sql.Row) (sql.Value, error) {
if len(row) == 0 {
return nil, fmt.Errorf("empty row")
return nil, errors.New("empty row")
}

if int(c.Position) > len(row) {
Expand Down
3 changes: 2 additions & 1 deletion internal/sql/expr/expression.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package expr

import (
"errors"
"fmt"

"github.com/i-sevostyanov/NanoDB/internal/sql"
Expand Down Expand Up @@ -37,7 +38,7 @@ func walk(node ast.Expression, scheme sql.Scheme) (Node, error) {

func columnExpr(expr *ast.IdentExpr, scheme sql.Scheme) (Node, error) {
if scheme == nil {
return nil, fmt.Errorf("schema not provided")
return nil, errors.New("schema not provided")
}

definition, ok := scheme[expr.Name]
Expand Down
12 changes: 10 additions & 2 deletions internal/sql/expr/logical/and.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package logical

import (
"errors"
"fmt"

"github.com/i-sevostyanov/NanoDB/internal/sql"
Expand All @@ -12,8 +13,15 @@ func And(left, right sql.Value) (sql.Value, error) {
return nil, fmt.Errorf("and: unsupported operation for %T and %T values", left.Raw(), right.Raw())
}

lvalue := left.Raw().(bool)
rvalue := right.Raw().(bool)
lvalue, ok := left.Raw().(bool)
if !ok {
return nil, errors.New("and: left operand should be bool")
}

rvalue, ok := right.Raw().(bool)
if !ok {
return nil, errors.New("and: right operand should be bool")
}

return datatype.NewBoolean(lvalue && rvalue), nil
}
12 changes: 10 additions & 2 deletions internal/sql/expr/logical/or.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package logical

import (
"errors"
"fmt"

"github.com/i-sevostyanov/NanoDB/internal/sql"
Expand All @@ -12,8 +13,15 @@ func Or(left, right sql.Value) (sql.Value, error) {
return nil, fmt.Errorf("and: unsupported operation for %T and %T values", left.Raw(), right.Raw())
}

lvalue := left.Raw().(bool)
rvalue := right.Raw().(bool)
lvalue, ok := left.Raw().(bool)
if !ok {
return nil, errors.New("and: left operand should be bool")
}

rvalue, ok := right.Raw().(bool)
if !ok {
return nil, errors.New("and: right operand should be bool")
}

return datatype.NewBoolean(lvalue || rvalue), nil
}
4 changes: 4 additions & 0 deletions internal/sql/expr/math/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,19 @@ func Add(left, right sql.Value) (sql.Value, error) {
case sql.Float:
lvalue := left.Raw().(float64)
rvalue := right.Raw().(float64)

return datatype.NewFloat(lvalue + rvalue), nil
case sql.Integer:
lvalue := left.Raw().(int64)
rvalue := right.Raw().(int64)

return datatype.NewInteger(lvalue + rvalue), nil
case sql.Text:
lvalue := left.Raw().(string)
rvalue := right.Raw().(string)

return datatype.NewText(lvalue + rvalue), nil
default:
}
}

Expand Down
10 changes: 6 additions & 4 deletions internal/sql/expr/math/div.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package math

import (
"errors"
"fmt"

"github.com/i-sevostyanov/NanoDB/internal/sql"
Expand All @@ -19,7 +20,7 @@ func Div(left, right sql.Value) (sql.Value, error) {
rvalue := right.Raw().(float64)

if rvalue == 0 {
return nil, fmt.Errorf("division by zero")
return nil, errors.New("division by zero")
}

return datatype.NewFloat(lvalue / rvalue), nil
Expand All @@ -28,10 +29,11 @@ func Div(left, right sql.Value) (sql.Value, error) {
rvalue := right.Raw().(int64)

if rvalue == 0 {
return nil, fmt.Errorf("division by zero")
return nil, errors.New("division by zero")
}

return datatype.NewInteger(lvalue / rvalue), nil
default:
}
}

Expand All @@ -40,7 +42,7 @@ func Div(left, right sql.Value) (sql.Value, error) {
rvalue := right.Raw().(float64)

if rvalue == 0 {
return nil, fmt.Errorf("division by zero")
return nil, errors.New("division by zero")
}

return datatype.NewFloat(lvalue / rvalue), nil
Expand All @@ -51,7 +53,7 @@ func Div(left, right sql.Value) (sql.Value, error) {
rvalue := float64(right.Raw().(int64))

if rvalue == 0 {
return nil, fmt.Errorf("division by zero")
return nil, errors.New("division by zero")
}

return datatype.NewFloat(lvalue / rvalue), nil
Expand Down
10 changes: 6 additions & 4 deletions internal/sql/expr/math/mod.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package math

import (
"errors"
"fmt"
"math"

Expand All @@ -20,7 +21,7 @@ func Mod(left, right sql.Value) (sql.Value, error) {
rvalue := right.Raw().(float64)

if rvalue == 0 {
return nil, fmt.Errorf("division by zero")
return nil, errors.New("division by zero")
}

return datatype.NewFloat(math.Mod(lvalue, rvalue)), nil
Expand All @@ -29,10 +30,11 @@ func Mod(left, right sql.Value) (sql.Value, error) {
rvalue := right.Raw().(int64)

if rvalue == 0 {
return nil, fmt.Errorf("division by zero")
return nil, errors.New("division by zero")
}

return datatype.NewInteger(lvalue % rvalue), nil
default:
}
}

Expand All @@ -41,7 +43,7 @@ func Mod(left, right sql.Value) (sql.Value, error) {
rvalue := right.Raw().(float64)

if rvalue == 0 {
return nil, fmt.Errorf("division by zero")
return nil, errors.New("division by zero")
}

return datatype.NewFloat(math.Mod(lvalue, rvalue)), nil
Expand All @@ -52,7 +54,7 @@ func Mod(left, right sql.Value) (sql.Value, error) {
rvalue := float64(right.Raw().(int64))

if rvalue == 0 {
return nil, fmt.Errorf("division by zero")
return nil, errors.New("division by zero")
}

return datatype.NewFloat(math.Mod(lvalue, rvalue)), nil
Expand Down
3 changes: 3 additions & 0 deletions internal/sql/expr/math/mul.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ func Mul(left, right sql.Value) (sql.Value, error) {
case sql.Float:
lvalue := left.Raw().(float64)
rvalue := right.Raw().(float64)

return datatype.NewFloat(lvalue * rvalue), nil
case sql.Integer:
lvalue := left.Raw().(int64)
rvalue := right.Raw().(int64)

return datatype.NewInteger(lvalue * rvalue), nil
default:
}
}

Expand Down
3 changes: 3 additions & 0 deletions internal/sql/expr/math/pow.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ func Pow(left, right sql.Value) (sql.Value, error) {
case sql.Float:
lvalue := left.Raw().(float64)
rvalue := right.Raw().(float64)

return datatype.NewFloat(math.Pow(lvalue, rvalue)), nil
case sql.Integer:
lvalue := left.Raw().(int64)
rvalue := right.Raw().(int64)

return datatype.NewFloat(math.Pow(float64(lvalue), float64(rvalue))), nil
default:
}
}

Expand Down
3 changes: 3 additions & 0 deletions internal/sql/expr/math/sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ func Sub(left, right sql.Value) (sql.Value, error) {
case sql.Float:
lvalue := left.Raw().(float64)
rvalue := right.Raw().(float64)

return datatype.NewFloat(lvalue - rvalue), nil
case sql.Integer:
lvalue := left.Raw().(int64)
rvalue := right.Raw().(int64)

return datatype.NewInteger(lvalue - rvalue), nil
default:
}
}

Expand Down
2 changes: 2 additions & 0 deletions internal/sql/expr/math/unary_minus.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ func UnaryMinus(value sql.Value) (sql.Value, error) {
switch value.DataType() {
case sql.Float:
v := value.Raw().(float64)

return datatype.NewFloat(-v), nil
case sql.Integer:
v := value.Raw().(int64)

return datatype.NewInteger(-v), nil
default:
return nil, fmt.Errorf("unary-minus: unsupported operand %T", value.Raw())
Expand Down
2 changes: 2 additions & 0 deletions internal/sql/expr/math/unary_plus.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ func UnaryPlus(value sql.Value) (sql.Value, error) {
switch value.DataType() {
case sql.Float:
v := value.Raw().(float64)

return datatype.NewFloat(v), nil
case sql.Integer:
v := value.Raw().(int64)

return datatype.NewInteger(v), nil
default:
return nil, fmt.Errorf("unary-plus: unsupported operand %T", value.Raw())
Expand Down
4 changes: 2 additions & 2 deletions internal/sql/expr/unary_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package expr_test

import (
"fmt"
"errors"
"math"
"testing"

Expand Down Expand Up @@ -135,7 +135,7 @@ func TestUnary_Eval(t *testing.T) {
defer ctrl.Finish()

operand := expr.NewMockNode(ctrl)
expected := fmt.Errorf("something went wrong")
expected := errors.New("something went wrong")
unaryExpr := expr.Unary{
Operator: expr.UnaryMinus,
Operand: operand,
Expand Down
2 changes: 1 addition & 1 deletion internal/sql/parsing/ast/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

// Node represents AST-node of the syntax tree for SQL query.
type Node interface{}
type Node any

// Statement represents syntax tree node of SQL statement (like: SELECT).
type Statement interface {
Expand Down
Loading