diff --git a/go/go.mod b/go/go.mod index cf62764de1..ccff768812 100644 --- a/go/go.mod +++ b/go/go.mod @@ -19,7 +19,7 @@ require ( github.com/dolthub/ishell v0.0.0-20220112232610-14e753f0f371 github.com/dolthub/mmap-go v1.0.4-0.20201107010347-f9f2a9588a66 github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 - github.com/dolthub/vitess v0.0.0-20220317184555-442cf0a796cc + github.com/dolthub/vitess v0.0.0-20220321185459-a24823fdb878 github.com/dustin/go-humanize v1.0.0 github.com/fatih/color v1.9.0 github.com/flynn-archive/go-shlex v0.0.0-20150515145356-3f9db97f8568 @@ -68,7 +68,7 @@ require ( ) require ( - github.com/dolthub/go-mysql-server v0.11.1-0.20220318174955-93a6edd8d585 + github.com/dolthub/go-mysql-server v0.11.1-0.20220321200512-c3002bdd2c8a github.com/google/flatbuffers v2.0.5+incompatible github.com/gosuri/uilive v0.0.4 github.com/kch42/buzhash v0.0.0-20160816060738-9bdec3dec7c6 diff --git a/go/go.sum b/go/go.sum index 9a46c718d9..122286fd3e 100755 --- a/go/go.sum +++ b/go/go.sum @@ -170,8 +170,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U= github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0= -github.com/dolthub/go-mysql-server v0.11.1-0.20220318174955-93a6edd8d585 h1:B/9vfwwCndGlyoX2bPo1xZoTTij9YIRUG0PcOYH/1G4= -github.com/dolthub/go-mysql-server v0.11.1-0.20220318174955-93a6edd8d585/go.mod h1:tctGAo2umfCywx3/3S6f8rvyUu2FpkdO2H2Bx4E9PJY= +github.com/dolthub/go-mysql-server v0.11.1-0.20220321200512-c3002bdd2c8a h1:sS3BYD81rmbs3c3tdUR5g2RRueKxq0dyBF1hQF/Aip8= +github.com/dolthub/go-mysql-server v0.11.1-0.20220321200512-c3002bdd2c8a/go.mod h1:vAqHI63UlUri4M9yC/GZAF390YZYP4y3tpDZ9KWzKlg= github.com/dolthub/ishell v0.0.0-20220112232610-14e753f0f371 h1:oyPHJlzumKta1vnOQqUnfdz+pk3EmnHS3Nd0cCT0I2g= github.com/dolthub/ishell v0.0.0-20220112232610-14e753f0f371/go.mod h1:dhGBqcCEfK5kuFmeO5+WOx3hqc1k3M29c1oS/R7N4ms= github.com/dolthub/jsonpath v0.0.0-20210609232853-d49537a30474 h1:xTrR+l5l+1Lfq0NvhiEsctylXinUMFhhsqaEcl414p8= @@ -180,8 +180,8 @@ github.com/dolthub/mmap-go v1.0.4-0.20201107010347-f9f2a9588a66 h1:WRPDbpJWEnPxP github.com/dolthub/mmap-go v1.0.4-0.20201107010347-f9f2a9588a66/go.mod h1:N5ZIbMGuDUpTpOFQ7HcsN6WSIpTGQjHP+Mz27AfmAgk= github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81 h1:7/v8q9XGFa6q5Ap4Z/OhNkAMBaK5YeuEzwJt+NZdhiE= github.com/dolthub/sqllogictest/go v0.0.0-20201107003712-816f3ae12d81/go.mod h1:siLfyv2c92W1eN/R4QqG/+RjjX5W2+gCTRjZxBjI3TY= -github.com/dolthub/vitess v0.0.0-20220317184555-442cf0a796cc h1:p+9ivR8aqWgO3CkL61xxNSAUK6D01BScK7/fqaynyWA= -github.com/dolthub/vitess v0.0.0-20220317184555-442cf0a796cc/go.mod h1:qpZ4j0dval04OgZJ5fyKnlniSFUosTH280pdzUjUJig= +github.com/dolthub/vitess v0.0.0-20220321185459-a24823fdb878 h1:i3U7Vppl2PuubOH6+EF13elXNUfBz1/CksCxyCn94qY= +github.com/dolthub/vitess v0.0.0-20220321185459-a24823fdb878/go.mod h1:qpZ4j0dval04OgZJ5fyKnlniSFUosTH280pdzUjUJig= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= diff --git a/go/libraries/doltcore/doltdb/doltdb_test.go b/go/libraries/doltcore/doltdb/doltdb_test.go index 88a9769da1..7857cc01b7 100644 --- a/go/libraries/doltcore/doltdb/doltdb_test.go +++ b/go/libraries/doltcore/doltdb/doltdb_test.go @@ -123,7 +123,6 @@ func TestIsValidTableName(t *testing.T) { assert.False(t, IsValidTableName("-")) assert.False(t, IsValidTableName("-a")) assert.False(t, IsValidTableName("")) - assert.False(t, IsValidTableName("1a")) assert.False(t, IsValidTableName("a1-")) assert.False(t, IsValidTableName("ab!!c")) } diff --git a/go/libraries/doltcore/doltdb/table.go b/go/libraries/doltcore/doltdb/table.go index 83146a047a..d0bf391b8e 100644 --- a/go/libraries/doltcore/doltdb/table.go +++ b/go/libraries/doltcore/doltdb/table.go @@ -19,6 +19,8 @@ import ( "errors" "fmt" "regexp" + "strings" + "unicode" "github.com/dolthub/go-mysql-server/sql" @@ -54,6 +56,8 @@ var ( // IsValidTableName returns true if the name matches the regular expression TableNameRegexStr. // Table names must be composed of 1 or more letters and non-initial numerals, as well as the characters _ and - func IsValidTableName(name string) bool { + // Ignore all leading digits + name = strings.TrimLeftFunc(name, unicode.IsDigit) return tableNameRegex.MatchString(name) } diff --git a/go/libraries/doltcore/sqle/sqlddl_test.go b/go/libraries/doltcore/sqle/sqlddl_test.go index 8209fa9abe..4005761529 100644 --- a/go/libraries/doltcore/sqle/sqlddl_test.go +++ b/go/libraries/doltcore/sqle/sqlddl_test.go @@ -83,11 +83,6 @@ func TestCreateTable(t *testing.T) { query: "create table dolt_table (id int primary key, age int)", expectedErr: "Invalid table name", }, - { - name: "Test bad table name begins with number", - query: "create table 1testTable (id int primary key, age int)", - expectedErr: "syntax error", - }, { name: "Test in use table name", query: "create table people (id int primary key, age int)", @@ -1125,6 +1120,14 @@ func TestRenameTable(t *testing.T) { expectedSchema: AppearancesTestSchema, expectedRows: AllAppsRows, }, + { + name: "alter rename table with alter syntax", + query: "alter table people rename to 123People", + oldTableName: "people", + newTableName: "123People", + expectedSchema: PeopleTestSchema, + expectedRows: AllPeopleRows, + }, { name: "table not found", query: "rename table notFound to newNowFound", @@ -1278,6 +1281,13 @@ func TestParseCreateTableStatement(t *testing.T) { expectedSchema: dtestutils.CreateSchema( schemaNewColumn(t, "id", 4817, sql.Int32, true, schema.NotNullConstraint{})), }, + { + name: "Test create table starting with number", + query: "create table 123table (id int primary key)", + expectedTable: "`123table`", + expectedSchema: dtestutils.CreateSchema( + schemaNewColumn(t, "id", 4817, sql.Int32, true, schema.NotNullConstraint{})), + }, { name: "Test create two column schema", query: "create table testTable (id int primary key, age int)", @@ -1292,11 +1302,6 @@ func TestParseCreateTableStatement(t *testing.T) { expectedTable: "testTable", expectedErr: "syntax error", }, - { - name: "Test bad table name begins with number", - query: "create table 1testTable (id int primary key, age int)", - expectedErr: "syntax error", - }, { name: "Test types", query: `create table testTable (