diff --git a/go/vt/schemadiff/schema_diff_test.go b/go/vt/schemadiff/schema_diff_test.go index 3dc1ab291fd..ac3a921acc5 100644 --- a/go/vt/schemadiff/schema_diff_test.go +++ b/go/vt/schemadiff/schema_diff_test.go @@ -415,13 +415,15 @@ func TestSchemaDiff(t *testing.T) { instantCapability: InstantDDLCapabilityIrrelevant, }, { - name: "add view with over", + name: "add view with over and keyword table", toQueries: append( createQueries, - "create view v2 as SELECT *, ROW_NUMBER() OVER(PARTITION BY info) AS row_num1, ROW_NUMBER() OVER(PARTITION BY info ORDER BY id) AS row_num2 FROM t1;\n", + "create table `order` (id int primary key, info int not null);", + "create view v2 as SELECT *, ROW_NUMBER() OVER(PARTITION BY info) AS row_num1, ROW_NUMBER() OVER(PARTITION BY info ORDER BY id) AS row_num2 FROM `order`;", ), - expectDiffs: 1, - entityOrder: []string{"v2"}, + expectDiffs: 2, + expectDeps: 1, + entityOrder: []string{"order", "v2"}, instantCapability: InstantDDLCapabilityIrrelevant, }, { diff --git a/go/vt/schemadiff/schema_test.go b/go/vt/schemadiff/schema_test.go index 7eab685f0d7..23782e676a1 100644 --- a/go/vt/schemadiff/schema_test.go +++ b/go/vt/schemadiff/schema_test.go @@ -125,6 +125,15 @@ func TestNewSchemaFromQueriesUnresolved(t *testing.T) { assert.Equal(t, "CREATE VIEW `v7` AS SELECT * FROM `v8`, `t2`", v.Create().CanonicalStatementString()) } +func TestNewSchemaFromQueriesWithSQLKeyword(t *testing.T) { + queries := []string{ + "create table `order` (id int primary key, info int not null)", + "create view v2 as SELECT *, ROW_NUMBER() OVER(PARTITION BY info) AS row_num1, ROW_NUMBER() OVER(PARTITION BY info ORDER BY id) AS row_num2 FROM `order`;", + } + _, err := NewSchemaFromQueries(NewTestEnv(), queries) + assert.NoError(t, err) +} + func TestNewSchemaFromQueriesUnresolvedAlias(t *testing.T) { // v8 does not exist queries := append(schemaTestCreateQueries, diff --git a/go/vt/schemadiff/semantics.go b/go/vt/schemadiff/semantics.go index ccbf654f566..cbba8c79497 100644 --- a/go/vt/schemadiff/semantics.go +++ b/go/vt/schemadiff/semantics.go @@ -51,7 +51,7 @@ func newDeclarativeSchemaInformation(env *Environment) *declarativeSchemaInforma // FindTableOrVindex implements the SchemaInformation interface func (si *declarativeSchemaInformation) FindTableOrVindex(tablename sqlparser.TableName) (*vindexes.Table, vindexes.Vindex, string, topodatapb.TabletType, key.Destination, error) { - table := si.Tables[sqlparser.String(tablename)] + table := si.Tables[tablename.Name.String()] return table, nil, "", 0, nil, nil }