From 8315bfdd08af74625a4744678d7e3ac58bf14ee5 Mon Sep 17 00:00:00 2001 From: kuba-- Date: Tue, 13 Nov 2018 11:04:43 +0100 Subject: [PATCH] upgrade vitess to v1.4.0 Signed-off-by: kuba-- --- engine_test.go | 17 ++++++++++++++++- go.mod | 2 +- sql/parse/parse.go | 15 ++++++++++----- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/engine_test.go b/engine_test.go index 372fed174..dacc1ae04 100644 --- a/engine_test.go +++ b/engine_test.go @@ -65,6 +65,10 @@ var queries = []struct { "SELECT substring(s, 2, 3) FROM mytable", []sql.Row{{"irs"}, {"eco"}, {"hir"}}, }, + { + `SELECT substring("foo", 2, 2)`, + []sql.Row{{"oo"}}, + }, { "SELECT YEAR('2007-12-11') FROM mytable", []sql.Row{{int32(2007)}, {int32(2007)}, {int32(2007)}}, @@ -137,6 +141,12 @@ var queries = []struct { {"first", "irst", "rst"}, }, }, + { + `SELECT substring("first", 1), substring("second", 2), substring("third", 3)`, + []sql.Row{ + {"first", "econd", "ird"}, + }, + }, { "SELECT substring(s2, -1), substring(s2, -2), substring(s2, -3) FROM othertable ORDER BY i2", []sql.Row{ @@ -145,7 +155,12 @@ var queries = []struct { {"t", "st", "rst"}, }, }, - + { + `SELECT substring("first", -1), substring("second", -2), substring("third", -3)`, + []sql.Row{ + {"t", "nd", "ird"}, + }, + }, { "SELECT s FROM mytable INNER JOIN othertable " + "ON substring(s2, 1, 2) != '' AND i = i2", diff --git a/go.mod b/go.mod index a0777c349..6bddc5dd9 100644 --- a/go.mod +++ b/go.mod @@ -10,5 +10,5 @@ require ( golang.org/x/net v0.0.0-20181029044818-c44066c5c816 // indirect google.golang.org/grpc v1.16.0 // indirect gopkg.in/src-d/go-errors.v1 v1.0.0 - gopkg.in/src-d/go-vitess.v1 v1.3.0 + gopkg.in/src-d/go-vitess.v1 v1.4.0 ) diff --git a/sql/parse/parse.go b/sql/parse/parse.go index d04885481..922964323 100644 --- a/sql/parse/parse.go +++ b/sql/parse/parse.go @@ -318,10 +318,7 @@ func convertCreateTable(c *sqlparser.DDL) (sql.Node, error) { } return plan.NewCreateTable( - sql.UnresolvedDatabase(""), - c.NewName.Name.String(), - schema, - ), nil + sql.UnresolvedDatabase(""), c.Table.Name.String(), schema), nil } func convertInsert(ctx *sql.Context, i *sqlparser.Insert) (sql.Node, error) { @@ -656,7 +653,15 @@ func exprToExpression(e sqlparser.Expr) (sql.Expression, error) { case *sqlparser.Default: return expression.NewDefaultColumn(v.ColName), nil case *sqlparser.SubstrExpr: - name, err := exprToExpression(v.Name) + var ( + name sql.Expression + err error + ) + if v.Name != nil { + name, err = exprToExpression(v.Name) + } else { + name, err = exprToExpression(v.StrVal) + } if err != nil { return nil, err }