Skip to content
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
4 changes: 4 additions & 0 deletions git/commits.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ func newCommitsRelation(r *git.Repository) sql.PhysicalRelation {
return &commitsRelation{r: r}
}

func (commitsRelation) Resolved() bool {
return true
}

func (commitsRelation) Name() string {
return commitsRelationName
}
Expand Down
4 changes: 4 additions & 0 deletions mem/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ func NewTable(name string, schema sql.Schema) *Table {
}
}

func (Table) Resolved() bool {
return true
}

func (t *Table) Name() string {
return t.name
}
Expand Down
5 changes: 5 additions & 0 deletions sql/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ type Nameable interface {
Name() string
}

type Resolvable interface {
Resolved() bool
}

type Node interface {
Resolvable
Schema() Schema
Children() []Node
RowIter() (RowIter, error)
Expand Down
1 change: 1 addition & 0 deletions sql/expression.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sql

type Expression interface {
Resolvable
Type() Type
Name() string
Eval(Row) interface{}
Expand Down
10 changes: 5 additions & 5 deletions sql/expression/boolean.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ package expression
import "github.com/mvader/gitql/sql"

type Not struct {
child sql.Expression
UnaryExpression
}

func NewNot(child sql.Expression) (*Not, error) {
return &Not{child: child}, nil
func NewNot(child sql.Expression) *Not {
return &Not{UnaryExpression{child}}
}

func (e Not) Type() sql.Type {
return sql.Boolean
}

func (e Not) Eval(row sql.Row) interface{} {
return !e.child.Eval(row).(bool)
return !e.Child.Eval(row).(bool)
}

func (e Not) Name() string {
return "Not(" + e.child.Name() + ")"
return "Not(" + e.Child.Name() + ")"
}
8 changes: 8 additions & 0 deletions sql/expression/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ type UnaryExpression struct {
Child sql.Expression
}

func (p UnaryExpression) Resolved() bool {
return p.Child.Resolved()
}

type BinaryExpression struct {
Left sql.Expression
Right sql.Expression
}

func (p BinaryExpression) Resolved() bool {
return p.Left.Resolved() && p.Right.Resolved()
}
2 changes: 1 addition & 1 deletion sql/expression/comparison.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (e LessThanOrEqual) Eval(row sql.Row) interface{} {
}

func checkEqualTypes(a sql.Expression, b sql.Expression) {
if a.Type() != b.Type() {
if a.Resolved() && b.Resolved() && a.Type() != b.Type() {
panic(fmt.Errorf("both types should be equal: %v and %v\n", a, b))
}
}
Expand Down
4 changes: 4 additions & 0 deletions sql/expression/get_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func NewGetField(index int, fieldType sql.Type, fieldName string) *GetField {
}
}

func (p GetField) Resolved() bool {
return true
}

func (p GetField) Type() sql.Type {
return p.fieldType
}
Expand Down
26 changes: 0 additions & 26 deletions sql/expression/identifier.go

This file was deleted.

4 changes: 4 additions & 0 deletions sql/expression/literal.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func NewLiteral(value interface{}, fieldType sql.Type) *Literal {
}
}

func (p Literal) Resolved() bool {
return true
}

func (p Literal) Type() sql.Type {
return p.fieldType
}
Expand Down
27 changes: 27 additions & 0 deletions sql/expression/unresolved.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package expression

import "github.com/mvader/gitql/sql"

type UnresolvedColumn struct {
name string
}

func NewUnresolvedColumn(name string) *UnresolvedColumn {
return &UnresolvedColumn{name}
}

func (UnresolvedColumn) Resolved() bool {
return false
}

func (UnresolvedColumn) Type() sql.Type {
return sql.String //FIXME
}

func (c UnresolvedColumn) Name() string {
return c.name
}

func (UnresolvedColumn) Eval(r sql.Row) interface{} {
return "FAIL" //FIXME
}
18 changes: 18 additions & 0 deletions sql/expression/unresolved_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package expression

import (
"testing"

"github.com/mvader/gitql/sql"
"github.com/stretchr/testify/assert"
)

func TestUnresolvedExpression(t *testing.T) {
assert := assert.New(t)
var e sql.Expression = NewUnresolvedColumn("test_col")
assert.NotNil(e)
var o sql.Expression = NewEquals(e, e)
assert.NotNil(o)
o = NewNot(e)
assert.NotNil(o)
}
6 changes: 3 additions & 3 deletions sql/plan/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ func TestFilter(t *testing.T) {
assert.Nil(row)

f = NewFilter(expression.NewEquals(
expression.NewGetField(2, sql.String, "col3"),
expression.NewGetField(2, sql.Integer, "col3"),
expression.NewLiteral(int32(1111),
sql.String)), child)
sql.Integer)), child)

iter, err = f.RowIter()
assert.Nil(err)
Expand All @@ -63,7 +63,7 @@ func TestFilter(t *testing.T) {
assert.Equal(int64(2222), row.Fields()[3])

f = NewFilter(expression.NewEquals(
expression.NewGetField(3, sql.String, "col4"),
expression.NewGetField(3, sql.BigInteger, "col4"),
expression.NewLiteral(int64(4444), sql.BigInteger)),
child)

Expand Down
27 changes: 27 additions & 0 deletions sql/plan/unresolved.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package plan

import (
"fmt"

"github.com/mvader/gitql/sql"
)

type UnresolvedRelation struct {
Name string
}

func (UnresolvedRelation) Resolved() bool {
return false
}

func (UnresolvedRelation) Children() []sql.Node {
return []sql.Node{}
}

func (UnresolvedRelation) Schema() sql.Schema {
return sql.Schema{}
}

func (UnresolvedRelation) RowIter() (sql.RowIter, error) {
return nil, fmt.Errorf("unresolved relation")
}
14 changes: 14 additions & 0 deletions sql/plan/unresolved_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package plan

import (
"testing"

"github.com/mvader/gitql/sql"
"github.com/stretchr/testify/assert"
)

func TestUnresolvedRelation(t *testing.T) {
assert := assert.New(t)
var r sql.Node = &UnresolvedRelation{"test_table"}
assert.NotNil(r)
}