Skip to content

Commit

Permalink
Delete IsEqual method from Node type
Browse files Browse the repository at this point in the history
  • Loading branch information
asdine committed Jun 28, 2020
1 parent b9c4fa1 commit 8979f7f
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 192 deletions.
9 changes: 0 additions & 9 deletions sql/planner/deletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,6 @@ func NewDeletionNode(n Node, tableName string) Node {
}
}

func (n *deletionNode) IsEqual(other Node) bool {
if !n.node.IsEqual(other) {
return false
}

on := other.(*deletionNode)
return n.tableName == on.tableName
}

func (n *deletionNode) Bind(tx *database.Transaction, params []expr.Param) (err error) {
n.table, err = tx.GetTable(n.tableName)
return
Expand Down
18 changes: 0 additions & 18 deletions sql/planner/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ func NewTableInputNode(tableName string) Node {
}
}

func (n *tableInputNode) IsEqual(other Node) bool {
if !n.node.IsEqual(other) {
return false
}

on := other.(*tableInputNode)
return n.tableName == on.tableName
}

func (n *tableInputNode) Bind(tx *database.Transaction, params []expr.Param) (err error) {
n.tx = tx
n.params = params
Expand Down Expand Up @@ -88,15 +79,6 @@ func NewIndexInputNode(tableName, indexName string, iop IndexIteratorOperator, f
}
}

func (n *indexInputNode) IsEqual(other Node) bool {
if !n.node.IsEqual(other) {
return false
}

on := other.(*indexInputNode)
return n.tableName == on.tableName && n.indexName == on.indexName
}

func (n *indexInputNode) Bind(tx *database.Transaction, params []expr.Param) (err error) {
if n.table == nil {
n.table, err = tx.GetTable(n.tableName)
Expand Down
8 changes: 4 additions & 4 deletions sql/planner/optimizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestSplitANDConditionRule(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
res, err := planner.SplitANDConditionRule(planner.NewTree(test.root))
require.NoError(t, err)
require.True(t, res.Root.IsEqual(test.expected))
require.Equal(t, res.String(), planner.NewTree(test.expected).String())
})
}
}
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestPrecalculateExprRule(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
res, err := planner.PrecalculateExprRule(planner.NewTree(planner.NewSelectionNode(planner.NewTableInputNode("foo"), test.e)))
require.NoError(t, err)
require.True(t, res.Root.IsEqual(planner.NewSelectionNode(planner.NewTableInputNode("foo"), test.expected)))
require.Equal(t, res.String(), planner.NewTree(planner.NewSelectionNode(planner.NewTableInputNode("foo"), test.expected)).String())
})
}
}
Expand Down Expand Up @@ -197,7 +197,7 @@ func TestRemoveUnnecessarySelectionNodesRule(t *testing.T) {
res, err := planner.RemoveUnnecessarySelectionNodesRule(planner.NewTree(test.root))
require.NoError(t, err)
if test.expected != nil {
require.True(t, test.expected.IsEqual(res.Root))
require.Equal(t, planner.NewTree(test.expected).String(), res.String())
} else {
require.Equal(t, test.expected, res.Root)
}
Expand Down Expand Up @@ -367,7 +367,7 @@ func TestUseIndexBasedOnSelectionNodeRule(t *testing.T) {
res, err := planner.UseIndexBasedOnSelectionNodeRule(planner.NewTree(test.root))
require.NoError(t, err)
if test.expected != nil {
require.True(t, test.expected.IsEqual(res.Root))
require.Equal(t, planner.NewTree(test.expected).String(), res.String())
} else {
require.Equal(t, res.Root, res.Root)
}
Expand Down
41 changes: 0 additions & 41 deletions sql/planner/projection.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,47 +40,6 @@ func NewProjectionNode(n Node, expressions []ResultField, tableName string) Node
}
}

// IsEqual returns true if other is a *ProjectionNode and contains the
// same information.
func (n *ProjectionNode) IsEqual(other Node) bool {
if !n.node.IsEqual(other) {
return false
}

on := other.(*ProjectionNode)
if n.tableName != on.tableName {
return false
}

if len(n.Expressions) != len(on.Expressions) {
return false
}

for i := range n.Expressions {
switch t := n.Expressions[i].(type) {
case Wildcard:
if _, ok := on.Expressions[i].(Wildcard); !ok {
return false
}
case ResultFieldExpr:
rf, ok := on.Expressions[i].(ResultFieldExpr)
if !ok {
return false
}

if t.ExprName != rf.ExprName {
return false
}

if !expr.Equal(t.Expr, rf.Expr) {
return false
}
}
}

return true
}

// Bind database resources to this node.
func (n *ProjectionNode) Bind(tx *database.Transaction, params []expr.Param) (err error) {
n.tx = tx
Expand Down
9 changes: 0 additions & 9 deletions sql/planner/replacement.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,6 @@ func NewReplacementNode(n Node, tableName string) Node {
}
}

func (n *replacementNode) IsEqual(other Node) bool {
if !n.node.IsEqual(other) {
return false
}

on := other.(*replacementNode)
return n.tableName == on.tableName
}

func (n *replacementNode) Bind(tx *database.Transaction, params []expr.Param) (err error) {
n.table, err = tx.GetTable(n.tableName)
return
Expand Down
9 changes: 0 additions & 9 deletions sql/planner/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@ func NewSortNode(n Node, sortField expr.FieldSelector, direction scanner.Token)
}
}

func (n *sortNode) IsEqual(other Node) bool {
if !n.node.IsEqual(other) {
return false
}

on := other.(*sortNode)
return expr.Equal(n.sortField, on.sortField) && n.direction == on.direction
}

func (n *sortNode) Bind(tx *database.Transaction, params []expr.Param) (err error) {
return
}
Expand Down
75 changes: 0 additions & 75 deletions sql/planner/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ type Node interface {
Right() Node
SetLeft(Node)
SetRight(Node)
IsEqual(Node) bool
Bind(tx *database.Transaction, params []expr.Param) error
}

Expand Down Expand Up @@ -188,38 +187,6 @@ func (n *node) SetRight(rn Node) {
n.right = rn
}

func (n *node) IsEqual(other Node) bool {
if n == nil {
return other == nil
}

if other == nil {
return false
}

if n.op != other.Operation() {
return false
}

if n.left == nil {
if other.Left() != nil {
return false
}
} else if !n.left.IsEqual(other.Left()) {
return false
}

if n.right == nil {
if other.Right() != nil {
return false
}
} else if !n.right.IsEqual(other.Right()) {
return false
}

return true
}

type selectionNode struct {
node

Expand All @@ -242,14 +209,6 @@ func NewSelectionNode(n Node, cond expr.Expr) Node {
}
}

func (n *selectionNode) IsEqual(other Node) bool {
if !n.node.IsEqual(other) {
return false
}

return expr.Equal(n.cond, other.(*selectionNode).cond)
}

func (n *selectionNode) Bind(tx *database.Transaction, params []expr.Param) (err error) {
n.tx = tx
n.params = params
Expand Down Expand Up @@ -306,14 +265,6 @@ func NewLimitNode(n Node, limit int) Node {
}
}

func (n *limitNode) IsEqual(other Node) bool {
if !n.node.IsEqual(other) {
return false
}

return n.limit == other.(*limitNode).limit
}

func (n *limitNode) Bind(tx *database.Transaction, params []expr.Param) (err error) {
n.tx = tx
n.params = params
Expand Down Expand Up @@ -349,14 +300,6 @@ func NewOffsetNode(n Node, offset int) Node {
}
}

func (n *offsetNode) IsEqual(other Node) bool {
if !n.node.IsEqual(other) {
return false
}

return n.offset == other.(*offsetNode).offset
}

func (n *offsetNode) String() string {
return fmt.Sprintf("Offset(%d)", n.offset)
}
Expand Down Expand Up @@ -395,15 +338,6 @@ func NewSetNode(n Node, field string, e expr.Expr) Node {
}
}

func (n *setNode) IsEqual(other Node) bool {
if !n.node.IsEqual(other) {
return false
}

on := other.(*setNode)
return n.field == on.field && expr.Equal(n.e, on.e)
}

func (n *setNode) Bind(tx *database.Transaction, params []expr.Param) (err error) {
n.tx = tx
n.params = params
Expand Down Expand Up @@ -472,15 +406,6 @@ func NewUnsetNode(n Node, field string) Node {
}
}

func (n *unsetNode) IsEqual(other Node) bool {
if !n.node.IsEqual(other) {
return false
}

on := other.(*unsetNode)
return n.field == on.field
}

func (n *unsetNode) Bind(tx *database.Transaction, params []expr.Param) error {
return nil
}
Expand Down
27 changes: 0 additions & 27 deletions sql/planner/tree_test.go

This file was deleted.

0 comments on commit 8979f7f

Please sign in to comment.