Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sink(ticdc): Add DDL query into schema.json file #7834

Merged
merged 10 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions cdc/model/schema_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ func WrapTableInfo(schemaID int64, schemaName string, version uint64, info *mode
TableInfo: info,
SchemaID: schemaID,
TableName: TableName{
Schema: schemaName,
Table: info.Name.O,
TableID: info.ID,
Schema: schemaName,
Table: info.Name.O,
TableID: info.ID,
IsPartition: info.GetPartitionInfo() != nil,
},
Version: version,
columnsOffset: make(map[int64]int, len(info.Columns)),
Expand Down
10 changes: 5 additions & 5 deletions cdc/sinkv2/ddlsink/cloudstorage/cloud_storage_ddl_sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,24 @@ func NewCloudStorageDDLSink(ctx context.Context, sinkURI *url.URL) (*ddlSink, er
return d, nil
}

func (d *ddlSink) generateSchemaPath(def cloudstorage.TableDetail) string {
return fmt.Sprintf("%s/%s/%d/schema.json", def.Schema, def.Table, def.Version)
func generateSchemaPath(def cloudstorage.TableDefinition) string {
return fmt.Sprintf("%s/%s/%d/schema.json", def.Schema, def.Table, def.TableVersion)
}

func (d *ddlSink) WriteDDLEvent(ctx context.Context, ddl *model.DDLEvent) error {
var def cloudstorage.TableDetail
var def cloudstorage.TableDefinition

if ddl.TableInfo.TableInfo == nil {
return nil
}

def.FromTableInfo(ddl.TableInfo)
def.FromDDLEvent(ddl)
encodedDef, err := json.MarshalIndent(def, "", " ")
if err != nil {
return errors.Trace(err)
}

path := d.generateSchemaPath(def)
path := generateSchemaPath(def)
err = d.statistics.RecordDDLExecution(func() error {
err1 := d.storage.WriteFile(ctx, path, encodedDef)
if err1 != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func TestWriteDDLEvent(t *testing.T) {
require.Nil(t, err)

ddlEvent := &model.DDLEvent{
Type: timodel.ActionAddColumn,
Query: "alter table test.table1 add col2 varchar(64)",
TableInfo: &model.TableInfo{
Version: 100,
TableName: model.TableName{
Expand Down Expand Up @@ -70,7 +72,10 @@ func TestWriteDDLEvent(t *testing.T) {
require.JSONEq(t, `{
"Table": "table1",
"Schema": "test",
"Version": 100,
"Version": 1,
"TableVersion": 100,
"Query": "alter table test.table1 add col2 varchar(64)",
"Type": 5,
"TableColumns": [
{
"ColumnName": "col1",
Expand Down
Loading