From 6e32b62d6d13cfc964b1c82c0df958d247522670 Mon Sep 17 00:00:00 2001 From: JCOR11599 <30810879+JCOR11599@users.noreply.github.com> Date: Mon, 21 Mar 2022 20:07:42 +0000 Subject: [PATCH 1/7] [ga-bump-dep] Bump dependency in Dolt by JCOR11599 --- go/go.mod | 4 ++-- go/go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go/go.mod b/go/go.mod index 9a6077766f..39306b4585 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 91ea6f37c4..22244e983d 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= From 8bcd208c5c88e4d69779d94cc453be0a147c28b5 Mon Sep 17 00:00:00 2001 From: James Cor Date: Mon, 21 Mar 2022 16:03:04 -0700 Subject: [PATCH 2/7] update regex and tests --- go/libraries/doltcore/doltdb/table.go | 2 +- go/libraries/doltcore/sqle/sqlddl_test.go | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/go/libraries/doltcore/doltdb/table.go b/go/libraries/doltcore/doltdb/table.go index 83146a047a..605977d528 100644 --- a/go/libraries/doltcore/doltdb/table.go +++ b/go/libraries/doltcore/doltdb/table.go @@ -32,7 +32,7 @@ import ( const ( // TableNameRegexStr is the regular expression that valid tables must match. - TableNameRegexStr = `^[a-zA-Z]{1}$|^[a-zA-Z_]+[-_0-9a-zA-Z]*[0-9a-zA-Z]+$` + TableNameRegexStr = `^[-_0-9a-zA-Z]+$` // ForeignKeyNameRegexStr is the regular expression that valid foreign keys must match. // From the unquoted identifiers: https://dev.mysql.com/doc/refman/8.0/en/identifiers.html // We also allow the '-' character from quoted identifiers. diff --git a/go/libraries/doltcore/sqle/sqlddl_test.go b/go/libraries/doltcore/sqle/sqlddl_test.go index 8209fa9abe..70000bea0e 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)", @@ -1292,11 +1287,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 ( From bd0a407560d8345bad721c9111db39ab82197ffe Mon Sep 17 00:00:00 2001 From: James Cor Date: Mon, 21 Mar 2022 16:17:13 -0700 Subject: [PATCH 3/7] more tests fixed --- go/libraries/doltcore/doltdb/doltdb_test.go | 1 - go/libraries/doltcore/doltdb/table.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) 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 605977d528..95c6f0fcd2 100644 --- a/go/libraries/doltcore/doltdb/table.go +++ b/go/libraries/doltcore/doltdb/table.go @@ -32,7 +32,7 @@ import ( const ( // TableNameRegexStr is the regular expression that valid tables must match. - TableNameRegexStr = `^[-_0-9a-zA-Z]+$` + TableNameRegexStr = `^[a-zA-Z]{1}$|^[0-9a-zA-Z_]+[-_0-9a-zA-Z]*[0-9a-zA-Z]+$` // ForeignKeyNameRegexStr is the regular expression that valid foreign keys must match. // From the unquoted identifiers: https://dev.mysql.com/doc/refman/8.0/en/identifiers.html // We also allow the '-' character from quoted identifiers. From 506f4a02a4ca02f4c9e8fcaa4604e411a6a3d570 Mon Sep 17 00:00:00 2001 From: James Cor Date: Mon, 21 Mar 2022 16:59:55 -0700 Subject: [PATCH 4/7] fixing even more tests --- go/libraries/doltcore/doltdb/table.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/go/libraries/doltcore/doltdb/table.go b/go/libraries/doltcore/doltdb/table.go index 95c6f0fcd2..ad05f89630 100644 --- a/go/libraries/doltcore/doltdb/table.go +++ b/go/libraries/doltcore/doltdb/table.go @@ -32,7 +32,7 @@ import ( const ( // TableNameRegexStr is the regular expression that valid tables must match. - TableNameRegexStr = `^[a-zA-Z]{1}$|^[0-9a-zA-Z_]+[-_0-9a-zA-Z]*[0-9a-zA-Z]+$` + TableNameRegexStr = `^[a-zA-Z]{1}$|^[a-zA-Z_]+[-_0-9a-zA-Z]*[0-9a-zA-Z]+$` // ForeignKeyNameRegexStr is the regular expression that valid foreign keys must match. // From the unquoted identifiers: https://dev.mysql.com/doc/refman/8.0/en/identifiers.html // We also allow the '-' character from quoted identifiers. @@ -54,7 +54,15 @@ 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 { - return tableNameRegex.MatchString(name) + // Ignore all leading digits + // TODO: could just use strings.TrimLeftFunc with unicode.IsNumber + idx := 0 + for i, c := range name { + if !(c >= '0' && c <= '9') { + idx = i + } + } + return tableNameRegex.MatchString(name[idx:]) } // IsValidForeignKeyName returns true if the name matches the regular expression ForeignKeyNameRegexStr. From e450da8b53f43818852eaab99df5dbe3ae2ac65e Mon Sep 17 00:00:00 2001 From: James Cor Date: Mon, 21 Mar 2022 17:14:29 -0700 Subject: [PATCH 5/7] adsfasdfasdg --- go/libraries/doltcore/doltdb/table.go | 1 + 1 file changed, 1 insertion(+) diff --git a/go/libraries/doltcore/doltdb/table.go b/go/libraries/doltcore/doltdb/table.go index ad05f89630..39e39b83a9 100644 --- a/go/libraries/doltcore/doltdb/table.go +++ b/go/libraries/doltcore/doltdb/table.go @@ -60,6 +60,7 @@ func IsValidTableName(name string) bool { for i, c := range name { if !(c >= '0' && c <= '9') { idx = i + break } } return tableNameRegex.MatchString(name[idx:]) From 27d5a541cf7661a8f6695e1c18fd3279e1330c0e Mon Sep 17 00:00:00 2001 From: James Cor Date: Tue, 22 Mar 2022 10:10:30 -0700 Subject: [PATCH 6/7] changing to use strings and unicode --- go/libraries/doltcore/doltdb/table.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/go/libraries/doltcore/doltdb/table.go b/go/libraries/doltcore/doltdb/table.go index 39e39b83a9..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" @@ -55,15 +57,8 @@ var ( // 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 - // TODO: could just use strings.TrimLeftFunc with unicode.IsNumber - idx := 0 - for i, c := range name { - if !(c >= '0' && c <= '9') { - idx = i - break - } - } - return tableNameRegex.MatchString(name[idx:]) + name = strings.TrimLeftFunc(name, unicode.IsDigit) + return tableNameRegex.MatchString(name) } // IsValidForeignKeyName returns true if the name matches the regular expression ForeignKeyNameRegexStr. From 8dcdbd723c1ca1aa288601a9d02d1cc9ee3abcad Mon Sep 17 00:00:00 2001 From: James Cor Date: Tue, 22 Mar 2022 10:14:25 -0700 Subject: [PATCH 7/7] adding tests --- go/libraries/doltcore/sqle/sqlddl_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/go/libraries/doltcore/sqle/sqlddl_test.go b/go/libraries/doltcore/sqle/sqlddl_test.go index 70000bea0e..4005761529 100644 --- a/go/libraries/doltcore/sqle/sqlddl_test.go +++ b/go/libraries/doltcore/sqle/sqlddl_test.go @@ -1120,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", @@ -1273,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)",