| 1073 | } |
| 1074 | |
| 1075 | func (e *ExtractorOracle) parseDDLSQL(redoSQL string, segOwner string) (dataEvent common.DataEvent, err error) { |
| 1076 | e.logger.Debug("ddl stmt parse start", "redoSQL", redoSQL) |
| 1077 | stmt, err := oracleParser.Parser(redoSQL) |
| 1078 | if err != nil { |
| 1079 | e.logger.Error("ddl parse err", "redoSQL", redoSQL) |
| 1080 | return dataEvent, err |
| 1081 | } |
| 1082 | getSchemaName := func(schema *oracle_element.Identifier) string { |
| 1083 | schemaName := "" |
| 1084 | if schema == nil { |
| 1085 | schemaName = segOwner |
| 1086 | } else { |
| 1087 | schemaName = IdentifierToString(schema) |
| 1088 | } |
| 1089 | return schemaName |
| 1090 | } |
| 1091 | switch s := stmt[0].(type) { |
| 1092 | case *oracleAst.CreateTableStmt: |
| 1093 | schemaName := getSchemaName(s.TableName.Schema) |
| 1094 | tableName := IdentifierToString(s.TableName.Table) |
| 1095 | |
| 1096 | // database table structure record |
| 1097 | schemaConfig := e.findSchemaConfig(schemaName) |
| 1098 | tableConfig := findTableConfig(schemaConfig, tableName) |
| 1099 | ordinals := make(map[string]int, 0) |
| 1100 | tableConfig.OriginalTableColumns = &common.ColumnList{Ordinals: ordinals} |
| 1101 | |
| 1102 | // generate MySQL create table stmt |
| 1103 | createTableStmt := &ast.CreateTableStmt{ |
| 1104 | TemporaryKeyword: ast.TemporaryNone, |
| 1105 | Table: &ast.TableName{ |
| 1106 | Schema: model.NewCIStr(schemaName), |
| 1107 | Name: model.NewCIStr(tableName), |
| 1108 | }, |
| 1109 | Options: []*ast.TableOption{{ |
| 1110 | Tp: ast.TableOptionCharset, |
| 1111 | StrValue: "utf8mb4", |
| 1112 | }}, |
| 1113 | } |
| 1114 | var columns []*ast.ColumnDef |
| 1115 | var constraints []*ast.Constraint |
| 1116 | for _, ts := range s.RelTable.TableStructs { |
| 1117 | switch td := ts.(type) { |
| 1118 | case *oracleAst.ColumnDef: |
| 1119 | columns = append(columns, oracleTp2MySQLTp(td)) |
| 1120 | ordinals[IdentifierToString(td.ColumnName)] = len(ordinals) |
| 1121 | case *oracleAst.OutOfLineConstraint: |
| 1122 | keys := make([]*ast.IndexPartSpecification, 0) |
| 1123 | for i := range td.Columns { |
| 1124 | keys = append(keys, &ast.IndexPartSpecification{ |
| 1125 | Column: &ast.ColumnName{ |
| 1126 | Name: model.NewCIStr(td.Columns[i].Value), |
| 1127 | }, |
| 1128 | }) |
| 1129 | } |
| 1130 | constraints = append(constraints, &ast.Constraint{ |
| 1131 | Tp: constrainto2m[td.Type], |
| 1132 | Name: IdentifierToString(td.Name), |