зеркало из https://github.com/github/vitess-gh.git
add collation name to the typing we get from the schema tracker
Signed-off-by: Andres Taylor <andres@planetscale.com>
This commit is contained in:
Родитель
f4dfa41560
Коммит
23c7e13493
|
@ -97,15 +97,18 @@ select table_schema, table_name, column_name, ordinal_position, character_set_na
|
|||
from information_schema.columns
|
||||
where table_schema = database()`
|
||||
|
||||
// fetchColumns are the columns we fetch
|
||||
fetchColumns = "table_name, column_name, data_type, collation_name"
|
||||
|
||||
// FetchUpdatedTables queries fetches all information about updated tables
|
||||
FetchUpdatedTables = `select table_name, column_name, data_type
|
||||
FetchUpdatedTables = `select ` + fetchColumns + `
|
||||
from _vt.schemacopy
|
||||
where table_schema = database() and
|
||||
table_name in ::tableNames
|
||||
order by table_name, ordinal_position`
|
||||
|
||||
// FetchTables queries fetches all information about tables
|
||||
FetchTables = `select table_name, column_name, data_type
|
||||
FetchTables = `select ` + fetchColumns + `
|
||||
from _vt.schemacopy
|
||||
where table_schema = database()
|
||||
order by table_name, ordinal_position`
|
||||
|
|
|
@ -196,9 +196,10 @@ func (t *Tracker) updateTables(keyspace string, res *sqltypes.Result) {
|
|||
tbl := row[0].ToString()
|
||||
colName := row[1].ToString()
|
||||
colType := row[2].ToString()
|
||||
collation := row[3].ToString()
|
||||
|
||||
cType := sqlparser.ColumnType{Type: colType}
|
||||
col := vindexes.Column{Name: sqlparser.NewColIdent(colName), Type: cType.SQLType()}
|
||||
col := vindexes.Column{Name: sqlparser.NewColIdent(colName), Type: cType.SQLType(), CollationName: collation}
|
||||
cols := t.tables.get(keyspace, tbl)
|
||||
|
||||
t.tables.set(keyspace, tbl, append(cols, col))
|
||||
|
|
|
@ -50,7 +50,10 @@ func TestTracking(t *testing.T) {
|
|||
Shard: target.Shard,
|
||||
Type: target.TabletType,
|
||||
}
|
||||
fields := sqltypes.MakeTestFields("table_name|col_name|col_type", "varchar|varchar|varchar")
|
||||
fields := sqltypes.MakeTestFields(
|
||||
"table_name|col_name|col_type|collation_name",
|
||||
"varchar|varchar|varchar|varchar",
|
||||
)
|
||||
|
||||
type delta struct {
|
||||
result *sqltypes.Result
|
||||
|
@ -60,7 +63,7 @@ func TestTracking(t *testing.T) {
|
|||
d0 = delta{
|
||||
result: sqltypes.MakeTestResult(
|
||||
fields,
|
||||
"prior|id|int",
|
||||
"prior|id|int|",
|
||||
),
|
||||
updTbl: []string{"prior"},
|
||||
}
|
||||
|
@ -68,9 +71,9 @@ func TestTracking(t *testing.T) {
|
|||
d1 = delta{
|
||||
result: sqltypes.MakeTestResult(
|
||||
fields,
|
||||
"t1|id|int",
|
||||
"t1|name|varchar",
|
||||
"t2|id|varchar",
|
||||
"t1|id|int|",
|
||||
"t1|name|varchar|utf8_bin",
|
||||
"t2|id|varchar|utf8_bin",
|
||||
),
|
||||
updTbl: []string{"t1", "t2"},
|
||||
}
|
||||
|
@ -78,9 +81,9 @@ func TestTracking(t *testing.T) {
|
|||
d2 = delta{
|
||||
result: sqltypes.MakeTestResult(
|
||||
fields,
|
||||
"t2|id|varchar",
|
||||
"t2|name|varchar",
|
||||
"t3|id|datetime",
|
||||
"t2|id|varchar|utf8_bin",
|
||||
"t2|name|varchar|utf8_bin",
|
||||
"t3|id|datetime|",
|
||||
),
|
||||
updTbl: []string{"prior", "t1", "t2", "t3"},
|
||||
}
|
||||
|
@ -88,7 +91,7 @@ func TestTracking(t *testing.T) {
|
|||
d3 = delta{
|
||||
result: sqltypes.MakeTestResult(
|
||||
fields,
|
||||
"t4|name|varchar",
|
||||
"t4|name|varchar|utf8_bin",
|
||||
),
|
||||
updTbl: []string{"t4"},
|
||||
}
|
||||
|
@ -104,9 +107,9 @@ func TestTracking(t *testing.T) {
|
|||
exp: map[string][]vindexes.Column{
|
||||
"t1": {
|
||||
{Name: sqlparser.NewColIdent("id"), Type: querypb.Type_INT32},
|
||||
{Name: sqlparser.NewColIdent("name"), Type: querypb.Type_VARCHAR}},
|
||||
{Name: sqlparser.NewColIdent("name"), Type: querypb.Type_VARCHAR, CollationName: "utf8_bin"}},
|
||||
"t2": {
|
||||
{Name: sqlparser.NewColIdent("id"), Type: querypb.Type_VARCHAR}},
|
||||
{Name: sqlparser.NewColIdent("id"), Type: querypb.Type_VARCHAR, CollationName: "utf8_bin"}},
|
||||
"prior": {
|
||||
{Name: sqlparser.NewColIdent("id"), Type: querypb.Type_INT32}},
|
||||
},
|
||||
|
@ -115,8 +118,8 @@ func TestTracking(t *testing.T) {
|
|||
deltas: []delta{d0, d1, d2},
|
||||
exp: map[string][]vindexes.Column{
|
||||
"t2": {
|
||||
{Name: sqlparser.NewColIdent("id"), Type: querypb.Type_VARCHAR},
|
||||
{Name: sqlparser.NewColIdent("name"), Type: querypb.Type_VARCHAR}},
|
||||
{Name: sqlparser.NewColIdent("id"), Type: querypb.Type_VARCHAR, CollationName: "utf8_bin"},
|
||||
{Name: sqlparser.NewColIdent("name"), Type: querypb.Type_VARCHAR, CollationName: "utf8_bin"}},
|
||||
"t3": {
|
||||
{Name: sqlparser.NewColIdent("id"), Type: querypb.Type_DATETIME}},
|
||||
},
|
||||
|
@ -125,12 +128,12 @@ func TestTracking(t *testing.T) {
|
|||
deltas: []delta{d0, d1, d2, d3},
|
||||
exp: map[string][]vindexes.Column{
|
||||
"t2": {
|
||||
{Name: sqlparser.NewColIdent("id"), Type: querypb.Type_VARCHAR},
|
||||
{Name: sqlparser.NewColIdent("name"), Type: querypb.Type_VARCHAR}},
|
||||
{Name: sqlparser.NewColIdent("id"), Type: querypb.Type_VARCHAR, CollationName: "utf8_bin"},
|
||||
{Name: sqlparser.NewColIdent("name"), Type: querypb.Type_VARCHAR, CollationName: "utf8_bin"}},
|
||||
"t3": {
|
||||
{Name: sqlparser.NewColIdent("id"), Type: querypb.Type_DATETIME}},
|
||||
"t4": {
|
||||
{Name: sqlparser.NewColIdent("name"), Type: querypb.Type_VARCHAR}},
|
||||
{Name: sqlparser.NewColIdent("name"), Type: querypb.Type_VARCHAR, CollationName: "utf8_bin"}},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -112,8 +112,9 @@ type ColumnVindex struct {
|
|||
|
||||
// Column describes a column.
|
||||
type Column struct {
|
||||
Name sqlparser.ColIdent `json:"name"`
|
||||
Type querypb.Type `json:"type"`
|
||||
Name sqlparser.ColIdent `json:"name"`
|
||||
Type querypb.Type `json:"type"`
|
||||
CollationName string `json:"collation_name"`
|
||||
}
|
||||
|
||||
// MarshalJSON returns a JSON representation of Column.
|
||||
|
|
Загрузка…
Ссылка в новой задаче