Skip to content

Commit

Permalink
schemadiff: normalize index option value (string) (#11675)
Browse files Browse the repository at this point in the history
* more FULLTEXT unit tests

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>

* more tests

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>

* a failing test

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>

* normalizing index option string

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>

* lower case index string in ast_format

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
  • Loading branch information
shlomi-noach authored Nov 10, 2022
1 parent 1ace3b4 commit a2fad7e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions go/vt/schemadiff/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ func (c *CreateTableEntity) normalizeIndexOptions() {
idx.Info.Type = strings.ToLower(idx.Info.Type)
for _, opt := range idx.Options {
opt.Name = strings.ToLower(opt.Name)
opt.String = strings.ToLower(opt.String)
}
}
}
Expand Down
36 changes: 35 additions & 1 deletion go/vt/schemadiff/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,20 @@ func TestCreateTableDiff(t *testing.T) {
diff: "alter table t1 add fulltext key name_ft (`name`)",
cdiff: "ALTER TABLE `t1` ADD FULLTEXT KEY `name_ft` (`name`)",
},
{
name: "add one fulltext key with explicit parser",
from: "create table t1 (id int primary key, name tinytext not null)",
to: "create table t1 (id int primary key, name tinytext not null, fulltext key name_ft(name) with parser ngram)",
diff: "alter table t1 add fulltext key name_ft (`name`) with parser ngram",
cdiff: "ALTER TABLE `t1` ADD FULLTEXT KEY `name_ft` (`name`) WITH PARSER ngram",
},
{
name: "add one fulltext key and one normal key",
from: "create table t1 (id int primary key, name tinytext not null)",
to: "create table t1 (id int primary key, name tinytext not null, key name_idx(name(32)), fulltext key name_ft(name))",
diff: "alter table t1 add key name_idx (`name`(32)), add fulltext key name_ft (`name`)",
cdiff: "ALTER TABLE `t1` ADD KEY `name_idx` (`name`(32)), ADD FULLTEXT KEY `name_ft` (`name`)",
},
{
name: "add two fulltext keys, distinct statements",
from: "create table t1 (id int primary key, name1 tinytext not null, name2 tinytext not null)",
Expand All @@ -453,6 +467,26 @@ func TestCreateTableDiff(t *testing.T) {
diff: "alter table t1 add fulltext key name1_ft (name1), add fulltext key name2_ft (name2)",
cdiff: "ALTER TABLE `t1` ADD FULLTEXT KEY `name1_ft` (`name1`), ADD FULLTEXT KEY `name2_ft` (`name2`)",
},
{
name: "no fulltext diff",
from: "create table t1 (id int primary key, name tinytext not null, fulltext key name_ft(name) with parser ngram)",
to: "create table t1 (id int primary key, name tinytext not null, fulltext key name_ft(name) with parser ngram)",
},
{
name: "no fulltext diff, 2",
from: "create table t1 (id int primary key, name tinytext not null, fulltext key name_ft(name) with parser ngram)",
to: "create table t1 (id int primary key, name tinytext not null, fulltext key name_ft(name) WITH PARSER `ngram`)",
},
{
name: "no fulltext diff, 3",
from: "create table t1 (id int primary key, name tinytext not null, fulltext key name_ft(name) with parser ngram)",
to: "create table t1 (id int primary key, name tinytext not null, fulltext key name_ft(name) /*!50100 WITH PARSER `ngram` */)",
},
{
name: "no fulltext diff",
from: "create table t1 (id int primary key, name tinytext not null, fulltext key name_ft(name) with parser ngram)",
to: "create table t1 (id int primary key, name tinytext not null, fulltext key name_ft(name) with parser NGRAM)",
},
// CHECK constraints
{
name: "identical check constraints",
Expand Down Expand Up @@ -1678,7 +1712,7 @@ func TestNormalize(t *testing.T) {
{
name: "does not drop non-default index type",
from: "create table t (id int primary key, i1 int, key i1_idx(i1) using hash)",
to: "CREATE TABLE `t` (\n\t`id` int PRIMARY KEY,\n\t`i1` int,\n\tKEY `i1_idx` (`i1`) USING HASH\n)",
to: "CREATE TABLE `t` (\n\t`id` int PRIMARY KEY,\n\t`i1` int,\n\tKEY `i1_idx` (`i1`) USING hash\n)",
},
{
name: "drops default index visibility",
Expand Down
2 changes: 1 addition & 1 deletion go/vt/sqlparser/ast_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ func (idx *IndexDefinition) Format(buf *TrackedBuffer) {
for _, opt := range idx.Options {
buf.astPrintf(idx, " %s", opt.Name)
if opt.String != "" {
buf.astPrintf(idx, " %s", opt.String)
buf.astPrintf(idx, " %#s", opt.String)
} else if opt.Value != nil {
buf.astPrintf(idx, " %v", opt.Value)
}
Expand Down
4 changes: 4 additions & 0 deletions go/vt/sqlparser/tracked_buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ func TestCanonicalOutput(t *testing.T) {
"select char(77, 121, 83, 81, '76' using utf8mb4) from dual",
"SELECT CHAR(77, 121, 83, 81, '76' USING utf8mb4) FROM `dual`",
},
{
"create table t1 (id int primary key, name tinytext not null, fulltext key name_ft(name) with parser ngram)",
"CREATE TABLE `t1` (\n\t`id` int PRIMARY KEY,\n\t`name` tinytext NOT NULL,\n\tFULLTEXT KEY `name_ft` (`name`) WITH PARSER ngram\n)",
},
}

for _, tc := range testcases {
Expand Down

0 comments on commit a2fad7e

Please sign in to comment.