Skip to content

Commit

Permalink
*: fix TestBuildSchemaWithGlobalTemporaryTable with infoschema v2 (#5…
Browse files Browse the repository at this point in the history
  • Loading branch information
ywqzzy authored Mar 27, 2024
1 parent e925628 commit e4e08f0
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions pkg/infoschema/infoschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ func TestBuildSchemaWithGlobalTemporaryTable(t *testing.T) {
State: model.StatePublic,
}
dbInfos := []*model.DBInfo{dbInfo}
builder, err := infoschema.NewBuilder(re, nil, nil).InitWithDBInfos(dbInfos, nil, nil, 1)
data := infoschema.NewData()
builder, err := infoschema.NewBuilder(re, nil, data).InitWithDBInfos(dbInfos, nil, nil, 1)
require.NoError(t, err)
is := builder.Build(math.MaxUint64)
require.False(t, is.HasTemporaryTable())
Expand All @@ -364,7 +365,7 @@ func TestBuildSchemaWithGlobalTemporaryTable(t *testing.T) {
err := kv.RunInNewTxn(ctx, re.Store(), true, func(ctx context.Context, txn kv.Transaction) error {
m := meta.NewMeta(txn)
for _, change := range changes {
builder, err := infoschema.NewBuilder(re, nil, nil).InitWithOldInfoSchema(curIs)
builder, err := infoschema.NewBuilder(re, nil, data).InitWithOldInfoSchema(curIs)
require.NoError(t, err)
change(m, builder)
curIs = builder.Build(math.MaxUint64)
Expand All @@ -383,7 +384,7 @@ func TestBuildSchemaWithGlobalTemporaryTable(t *testing.T) {
State: model.StatePublic,
})
require.NoError(t, err)
_, err = builder.ApplyDiff(m, &model.SchemaDiff{Type: model.ActionCreateTable, SchemaID: db.ID, TableID: tblID})
_, err = builder.ApplyDiff(m, &model.SchemaDiff{Type: model.ActionCreateTable, SchemaID: db.ID, TableID: tblID, Version: 1})
require.NoError(t, err)
}
}
Expand All @@ -395,7 +396,7 @@ func TestBuildSchemaWithGlobalTemporaryTable(t *testing.T) {
State: model.StatePublic,
})
require.NoError(t, err)
_, err = builder.ApplyDiff(m, &model.SchemaDiff{Type: model.ActionCreateTable, SchemaID: db.ID, TableID: tblID})
_, err = builder.ApplyDiff(m, &model.SchemaDiff{Type: model.ActionCreateTable, SchemaID: db.ID, TableID: tblID, Version: 1})
require.NoError(t, err)
}
}
Expand All @@ -404,7 +405,7 @@ func TestBuildSchemaWithGlobalTemporaryTable(t *testing.T) {
return func(m *meta.Meta, builder *infoschema.Builder) {
err := m.DropTableOrView(db.ID, db.Name.L, tblID, "")
require.NoError(t, err)
_, err = builder.ApplyDiff(m, &model.SchemaDiff{Type: model.ActionDropTable, SchemaID: db.ID, TableID: tblID})
_, err = builder.ApplyDiff(m, &model.SchemaDiff{Type: model.ActionDropTable, SchemaID: db.ID, TableID: tblID, Version: 1})
require.NoError(t, err)
}
}
Expand All @@ -420,14 +421,14 @@ func TestBuildSchemaWithGlobalTemporaryTable(t *testing.T) {
State: model.StatePublic,
})
require.NoError(t, err)
_, err = builder.ApplyDiff(m, &model.SchemaDiff{Type: model.ActionTruncateTable, SchemaID: db.ID, OldTableID: tblID, TableID: newTblID})
_, err = builder.ApplyDiff(m, &model.SchemaDiff{Type: model.ActionTruncateTable, SchemaID: db.ID, OldTableID: tblID, TableID: newTblID, Version: 1})
require.NoError(t, err)
}
}

alterTableChange := func(tblID int64) func(m *meta.Meta, builder *infoschema.Builder) {
return func(m *meta.Meta, builder *infoschema.Builder) {
_, err := builder.ApplyDiff(m, &model.SchemaDiff{Type: model.ActionAddColumn, SchemaID: db.ID, TableID: tblID})
_, err := builder.ApplyDiff(m, &model.SchemaDiff{Type: model.ActionAddColumn, SchemaID: db.ID, TableID: tblID, Version: 1})
require.NoError(t, err)
}
}
Expand All @@ -441,9 +442,16 @@ func TestBuildSchemaWithGlobalTemporaryTable(t *testing.T) {
require.True(t, newIS.HasTemporaryTable())

// full load
data = infoschema.NewData()
newDB, ok := newIS.SchemaByName(model.NewCIStr("test"))
tables := newIS.SchemaTables(newDB.Name)
tblInfos := make([]*model.TableInfo, 0, len(tables))
for _, table := range tables {
tblInfos = append(tblInfos, table.Meta())
}
newDB.Tables = tblInfos
require.True(t, ok)
builder, err = infoschema.NewBuilder(re, nil, nil).InitWithDBInfos([]*model.DBInfo{newDB}, newIS.AllPlacementPolicies(), newIS.AllResourceGroups(), newIS.SchemaMetaVersion())
builder, err = infoschema.NewBuilder(re, nil, data).InitWithDBInfos([]*model.DBInfo{newDB}, newIS.AllPlacementPolicies(), newIS.AllResourceGroups(), newIS.SchemaMetaVersion())
require.NoError(t, err)
require.True(t, builder.Build(math.MaxUint64).HasTemporaryTable())

Expand Down

0 comments on commit e4e08f0

Please sign in to comment.