Skip to content

Commit

Permalink
Cherry-pick 92c25af with conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
vitess-bot[bot] authored and vitess-bot committed Jan 31, 2025
1 parent f4563b3 commit dc369cf
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
4 changes: 2 additions & 2 deletions go/vt/vtgate/schema/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ func (t *Tracker) updatedTableSchema(th *discovery.TabletHealth) bool {

func (t *Tracker) updateTables(keyspace string, res map[string]string) {
for tableName, tableDef := range res {
stmt, err := t.parser.Parse(tableDef)
stmt, err := t.parser.ParseStrictDDL(tableDef)
if err != nil {
log.Warningf("error parsing table definition for %s: %v", tableName, err)
continue
Expand Down Expand Up @@ -475,7 +475,7 @@ func (vm *viewMap) set(ks, tbl, sql string) {
m = make(map[tableNameStr]sqlparser.SelectStatement)
vm.m[ks] = m
}
stmt, err := vm.parser.Parse(sql)
stmt, err := vm.parser.ParseStrictDDL(sql)
if err != nil {
log.Warningf("ignoring view '%s', parsing error in view definition: '%s'", tbl, sql)
return
Expand Down
55 changes: 55 additions & 0 deletions go/vt/vtgate/schema/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func TestTrackerGetKeyspaceUpdateController(t *testing.T) {

// TestTableTracking tests that the tracker is able to track table schema changes.
func TestTableTracking(t *testing.T) {
<<<<<<< HEAD
schemaDefResult := []map[string]string{{
"prior": "create table prior(id int primary key)",
}, {
Expand All @@ -181,6 +182,26 @@ func TestTableTracking(t *testing.T) {
}, {
"t4": "create table t4(name varchar(50) primary key)",
}}
=======
schemaResponse := []sandboxconn.SchemaResult{
tables(tbl("prior", "create table prior(id int primary key)")),
empty(), /*initial load of view*/
tables(
tbl("t1", "create table t1(id bigint primary key, name varchar(50), email varchar(50) not null default 'a@b.com')"),
tbl("T1", "create table T1(id varchar(50) primary key)"),
),
tables(
tbl("T1", "create table T1(id varchar(50) primary key, name varchar(50))"),
tbl("t3", "create table t3(id datetime primary key)"),
),
tables(
tbl("t4", "create table t4(name varchar(50) primary key)"),
),
tables(
tbl("t5", "create table t5(name varchar(50) primary key with broken syntax)"),
),
}
>>>>>>> 92c25af2d6 (Fix panic inside schema tracker (#17659))

testcases := []testCases{{
testName: "initial table load",
Expand Down Expand Up @@ -212,13 +233,23 @@ func TestTableTracking(t *testing.T) {
"t3": {{Name: sqlparser.NewIdentifierCI("id"), Type: querypb.Type_DATETIME, CollationName: "binary", Size: 0, Nullable: true}},
"t4": {{Name: sqlparser.NewIdentifierCI("name"), Type: querypb.Type_VARCHAR, Size: 50, Nullable: true}},
},
}, {
testName: "new broken table",
updTbl: []string{"t5"},
expTbl: map[string][]vindexes.Column{
"t1": {{Name: sqlparser.NewIdentifierCI("id"), Type: querypb.Type_INT64, CollationName: "binary", Nullable: true}, {Name: sqlparser.NewIdentifierCI("name"), Type: querypb.Type_VARCHAR, Size: 50, Nullable: true}, {Name: sqlparser.NewIdentifierCI("email"), Type: querypb.Type_VARCHAR, Size: 50, Nullable: false, Default: &sqlparser.Literal{Val: "a@b.com"}}},
"T1": {{Name: sqlparser.NewIdentifierCI("id"), Type: querypb.Type_VARCHAR, Size: 50, Nullable: true}, {Name: sqlparser.NewIdentifierCI("name"), Type: querypb.Type_VARCHAR, Size: 50, Nullable: true}},
"t3": {{Name: sqlparser.NewIdentifierCI("id"), Type: querypb.Type_DATETIME, CollationName: "binary", Size: 0, Nullable: true}},
"t4": {{Name: sqlparser.NewIdentifierCI("name"), Type: querypb.Type_VARCHAR, Size: 50, Nullable: true}},
},
}}

testTracker(t, schemaDefResult, testcases)
}

// TestViewsTracking tests that the tracker is able to track views.
func TestViewsTracking(t *testing.T) {
<<<<<<< HEAD
schemaDefResult := []map[string]string{{
// initial load of table - kept empty
}, {
Expand All @@ -232,6 +263,22 @@ func TestViewsTracking(t *testing.T) {
}, {
"t4": "create view t4 as select 1 from tbl4",
}}
=======
schemaDefResult := []sandboxconn.SchemaResult{
empty(), /*initial load of view*/
tables(tbl("prior", "create view prior as select 1 from tbl")),
tables(
tbl("t1", "create view t1 as select 1 from tbl1"),
tbl("V1", "create view V1 as select 1 from tbl2"),
),
tables(
tbl("V1", "create view V1 as select 1,2 from tbl2"),
tbl("t3", "create view t3 as select 1 from tbl3"),
),
tables(tbl("t4", "create view t4 as select 1 from tbl4")),
tables(tbl("t4", "create view t5 as select 1 from tbl4 with broken syntax")),
}
>>>>>>> 92c25af2d6 (Fix panic inside schema tracker (#17659))

testcases := []testCases{{
testName: "initial view load",
Expand Down Expand Up @@ -259,6 +306,14 @@ func TestViewsTracking(t *testing.T) {
"V1": "select 1, 2 from tbl2",
"t3": "select 1 from tbl3",
"t4": "select 1 from tbl4"},
}, {
testName: "new broken t5",
updView: []string{"t5"},
expView: map[string]string{
"t1": "select 1 from tbl1",
"V1": "select 1, 2 from tbl2",
"t3": "select 1 from tbl3",
"t4": "select 1 from tbl4"},
}}

testTracker(t, schemaDefResult, testcases)
Expand Down
5 changes: 5 additions & 0 deletions go/vt/wrangler/vdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,13 @@ func findPKs(env *vtenv.Environment, table *tabletmanagerdatapb.TableDefinition,
// getColumnCollations determines the proper collation to use for each
// column in the table definition leveraging MySQL's collation inheritance
// rules.
<<<<<<< HEAD

Check failure on line 539 in go/vt/wrangler/vdiff.go

View workflow job for this annotation

GitHub Actions / Code Coverage

syntax error: non-declaration statement outside function body

Check failure on line 539 in go/vt/wrangler/vdiff.go

View workflow job for this annotation

GitHub Actions / Code Coverage

syntax error: non-declaration statement outside function body
func getColumnCollations(venv *vtenv.Environment, table *tabletmanagerdatapb.TableDefinition) (map[string]collations.ID, error) {
createstmt, err := venv.Parser().Parse(table.Schema)
=======

Check failure on line 542 in go/vt/wrangler/vdiff.go

View workflow job for this annotation

GitHub Actions / Code Coverage

syntax error: unexpected ==, expected }

Check failure on line 542 in go/vt/wrangler/vdiff.go

View workflow job for this annotation

GitHub Actions / Code Coverage

syntax error: unexpected ==, expected }
func getColumnCollations(venv *vtenv.Environment, table *tabletmanagerdatapb.TableDefinition) (map[string]collations.ID, map[string]*evalengine.EnumSetValues, error) {
createstmt, err := venv.Parser().ParseStrictDDL(table.Schema)
>>>>>>> 92c25af2d6 (Fix panic inside schema tracker (#17659))

Check failure on line 545 in go/vt/wrangler/vdiff.go

View workflow job for this annotation

GitHub Actions / Code Coverage

syntax error: unexpected >>, expected }

Check failure on line 545 in go/vt/wrangler/vdiff.go

View workflow job for this annotation

GitHub Actions / Code Coverage

invalid character U+0023 '#'

Check failure on line 545 in go/vt/wrangler/vdiff.go

View workflow job for this annotation

GitHub Actions / Code Coverage

syntax error: unexpected >>, expected }

Check failure on line 545 in go/vt/wrangler/vdiff.go

View workflow job for this annotation

GitHub Actions / Code Coverage

invalid character U+0023 '#'
if err != nil {
return nil, err
}
Expand Down
7 changes: 7 additions & 0 deletions go/vt/wrangler/vdiff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,13 @@ func TestGetColumnCollations(t *testing.T) {
"name": collationEnv.LookupByName("utf16_icelandic_ci"),
},
},
{
name: "invalid schema",
table: &tabletmanagerdatapb.TableDefinition{
Schema: "create table t1 (c1 varchar(10), size set('small', 'medium', 'large'), primary key(c1) with syntax error)",
},
wantErr: true,
},
}
env := vtenv.NewTestEnv()
for _, tt := range tests {
Expand Down

0 comments on commit dc369cf

Please sign in to comment.