Skip to content

Commit

Permalink
Merge branch 'master' into reparent-refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Anthony Yeh <[email protected]>
  • Loading branch information
enisoc committed Oct 16, 2019
2 parents 1bab089 + 74ca3b1 commit 191d5e5
Show file tree
Hide file tree
Showing 107 changed files with 6,149 additions and 3,646 deletions.
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ require (
github.com/golang/mock v1.3.1
github.com/golang/protobuf v1.3.2
github.com/golang/snappy v0.0.0-20170215233205-553a64147049
github.com/google/btree v1.0.0 // indirect
github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf // indirect
github.com/gorilla/websocket v0.0.0-20160912153041-2d1e4548da23
github.com/grpc-ecosystem/go-grpc-middleware v1.1.0
Expand All @@ -49,8 +48,6 @@ require (
github.com/minio/minio-go v0.0.0-20190131015406-c8a261de75c1
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/olekukonko/tablewriter v0.0.0-20160115111002-cca8bbc07984
github.com/opentracing-contrib/go-grpc v0.0.0-20180928155321-4b5a12d3ff02
github.com/opentracing/opentracing-go v1.1.0
Expand Down
212 changes: 106 additions & 106 deletions go/vt/proto/binlogdata/binlogdata.pb.go

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions go/vt/sqlparser/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,23 @@ func IsDML(sql string) bool {
return false
}

// SplitAndExpression breaks up the Expr into AND-separated conditions
// and appends them to filters. Outer parenthesis are removed. Precedence
// should be taken into account if expressions are recombined.
func SplitAndExpression(filters []Expr, node Expr) []Expr {
if node == nil {
return filters
}
switch node := node.(type) {
case *AndExpr:
filters = SplitAndExpression(filters, node.Left)
return SplitAndExpression(filters, node.Right)
case *ParenExpr:
return SplitAndExpression(filters, node.Expr)
}
return append(filters, node)
}

// GetTableName returns the table name from the SimpleTableExpr
// only if it's a simple expression. Otherwise, it returns "".
func GetTableName(node SimpleTableExpr) TableIdent {
Expand Down
46 changes: 46 additions & 0 deletions go/vt/sqlparser/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
"vitess.io/vitess/go/sqltypes"
)

Expand Down Expand Up @@ -111,6 +112,51 @@ func TestIsDML(t *testing.T) {
}
}

func TestSplitAndExpression(t *testing.T) {
testcases := []struct {
sql string
out []string
}{{
sql: "select * from t",
out: nil,
}, {
sql: "select * from t where a = 1",
out: []string{"a = 1"},
}, {
sql: "select * from t where a = 1 and b = 1",
out: []string{"a = 1", "b = 1"},
}, {
sql: "select * from t where a = 1 and (b = 1 and c = 1)",
out: []string{"a = 1", "b = 1", "c = 1"},
}, {
sql: "select * from t where a = 1 and (b = 1 or c = 1)",
out: []string{"a = 1", "b = 1 or c = 1"},
}, {
sql: "select * from t where a = 1 and b = 1 or c = 1",
out: []string{"a = 1 and b = 1 or c = 1"},
}, {
sql: "select * from t where a = 1 and b = 1 + (c = 1)",
out: []string{"a = 1", "b = 1 + (c = 1)"},
}, {
sql: "select * from t where (a = 1 and ((b = 1 and c = 1)))",
out: []string{"a = 1", "b = 1", "c = 1"},
}}
for _, tcase := range testcases {
stmt, err := Parse(tcase.sql)
assert.NoError(t, err)
var expr Expr
if where := stmt.(*Select).Where; where != nil {
expr = where.Expr
}
splits := SplitAndExpression(nil, expr)
var got []string
for _, split := range splits {
got = append(got, String(split))
}
assert.Equal(t, tcase.out, got)
}
}

func TestGetTableName(t *testing.T) {
testcases := []struct {
in, out string
Expand Down
6 changes: 6 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,12 @@ var (
}, {
input: "alter table a drop spatial index idx (id)",
output: "alter table a",
}, {
input: "alter table a add check ch_1",
output: "alter table a",
}, {
input: "alter table a drop check ch_1",
output: "alter table a",
}, {
input: "alter table a drop foreign key",
output: "alter table a",
Expand Down
Loading

0 comments on commit 191d5e5

Please sign in to comment.