mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
fixed format
This commit is contained in:
@@ -215,15 +215,13 @@ public class LogEventConvert extends AbstractCanalLifeCycle implements BinlogPar
|
|||||||
// 更新下table meta cache
|
// 更新下table meta cache
|
||||||
if (tableMetaCache != null
|
if (tableMetaCache != null
|
||||||
&& (result.getType() == EventType.ALTER || result.getType() == EventType.ERASE || result.getType() == EventType.RENAME)) {
|
&& (result.getType() == EventType.ALTER || result.getType() == EventType.ERASE || result.getType() == EventType.RENAME)) {
|
||||||
|
for (DdlResult renameResult = result; renameResult != null; renameResult = renameResult.getRenameTableResult()) {
|
||||||
for(DdlResult renameResult=result ;renameResult!=null; renameResult = renameResult.getRenameTableResult()) {
|
String schemaName0 = event.getDbName(); // 防止rename语句后产生schema变更带来影响
|
||||||
String schemaName0 = event.getDbName(); //防止 rename语句后产生 schema变更带来影响
|
|
||||||
if (StringUtils.isNotEmpty(renameResult.getSchemaName())) {
|
if (StringUtils.isNotEmpty(renameResult.getSchemaName())) {
|
||||||
schemaName0 = renameResult.getSchemaName();
|
schemaName0 = renameResult.getSchemaName();
|
||||||
}
|
}
|
||||||
|
|
||||||
tableName = renameResult.getTableName();
|
tableName = renameResult.getTableName();
|
||||||
|
|
||||||
if (StringUtils.isNotEmpty(tableName)) {
|
if (StringUtils.isNotEmpty(tableName)) {
|
||||||
// 如果解析到了正确的表信息,则根据全名进行清除
|
// 如果解析到了正确的表信息,则根据全名进行清除
|
||||||
tableMetaCache.clearTableMeta(schemaName0, tableName);
|
tableMetaCache.clearTableMeta(schemaName0, tableName);
|
||||||
|
|||||||
@@ -23,15 +23,15 @@ import com.alibaba.otter.canal.protocol.CanalEntry.EventType;
|
|||||||
*/
|
*/
|
||||||
public class SimpleDdlParser {
|
public class SimpleDdlParser {
|
||||||
|
|
||||||
public static final String CREATE_PATTERN = "^\\s*CREATE\\s*(TEMPORARY)?\\s*TABLE\\s*(.*)$";
|
public static final String CREATE_PATTERN = "^\\s*CREATE\\s*(TEMPORARY)?\\s*TABLE\\s*(.*)$";
|
||||||
public static final String DROP_PATTERN = "^\\s*DROP\\s*(TEMPORARY)?\\s*TABLE\\s*(.*)$";
|
public static final String DROP_PATTERN = "^\\s*DROP\\s*(TEMPORARY)?\\s*TABLE\\s*(.*)$";
|
||||||
public static final String ALERT_PATTERN = "^\\s*ALTER\\s*(IGNORE)?\\s*TABLE\\s*(.*)$";
|
public static final String ALERT_PATTERN = "^\\s*ALTER\\s*(IGNORE)?\\s*TABLE\\s*(.*)$";
|
||||||
public static final String TRUNCATE_PATTERN = "^\\s*TRUNCATE\\s*(TABLE)?\\s*(.*)$";
|
public static final String TRUNCATE_PATTERN = "^\\s*TRUNCATE\\s*(TABLE)?\\s*(.*)$";
|
||||||
public static final String TABLE_PATTERN = "^(IF\\s*NOT\\s*EXISTS\\s*)?(IF\\s*EXISTS\\s*)?(`?.+?`?[;\\(\\s]+?)?.*$"; // 采用非贪婪模式
|
public static final String TABLE_PATTERN = "^(IF\\s*NOT\\s*EXISTS\\s*)?(IF\\s*EXISTS\\s*)?(`?.+?`?[;\\(\\s]+?)?.*$"; // 采用非贪婪模式
|
||||||
public static final String INSERT_PATTERN = "^\\s*(INSERT|MERGE|REPLACE)(.*)$";
|
public static final String INSERT_PATTERN = "^\\s*(INSERT|MERGE|REPLACE)(.*)$";
|
||||||
public static final String UPDATE_PATTERN = "^\\s*UPDATE(.*)$";
|
public static final String UPDATE_PATTERN = "^\\s*UPDATE(.*)$";
|
||||||
public static final String DELETE_PATTERN = "^\\s*DELETE(.*)$";
|
public static final String DELETE_PATTERN = "^\\s*DELETE(.*)$";
|
||||||
public static final String RENAME_PATTERN = "^\\s*RENAME\\s*TABLE\\s*(.*?)\\s*TO\\s*(.*?)$";
|
public static final String RENAME_PATTERN = "^\\s*RENAME\\s*TABLE\\s*(.*?)\\s*TO\\s*(.*?)$";
|
||||||
public static final String RENAME_REMNANT_PATTERN = "^\\s*(.*?)\\s*TO\\s*(.*?)$";
|
public static final String RENAME_REMNANT_PATTERN = "^\\s*(.*?)\\s*TO\\s*(.*?)$";
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
@@ -43,8 +43,8 @@ public class SimpleDdlParser {
|
|||||||
* http://dev.mysql.com/doc/refman/5.6/en/create-index.html
|
* http://dev.mysql.com/doc/refman/5.6/en/create-index.html
|
||||||
* </pre>
|
* </pre>
|
||||||
*/
|
*/
|
||||||
public static final String CREATE_INDEX_PATTERN = "^\\s*CREATE\\s*(UNIQUE)?(FULLTEXT)?(SPATIAL)?\\s*INDEX\\s*(.*?)\\s*ON\\s*(.*?)$";
|
public static final String CREATE_INDEX_PATTERN = "^\\s*CREATE\\s*(UNIQUE)?(FULLTEXT)?(SPATIAL)?\\s*INDEX\\s*(.*?)\\s*ON\\s*(.*?)$";
|
||||||
public static final String DROP_INDEX_PATTERN = "^\\s*DROP\\s*INDEX\\s*(.*?)\\s*ON\\s*(.*?)$";
|
public static final String DROP_INDEX_PATTERN = "^\\s*DROP\\s*INDEX\\s*(.*?)\\s*ON\\s*(.*?)$";
|
||||||
|
|
||||||
public static DdlResult parse(String queryString, String schmeaName) {
|
public static DdlResult parse(String queryString, String schmeaName) {
|
||||||
queryString = removeComment(queryString); // 去除/* */的sql注释内容
|
queryString = removeComment(queryString); // 去除/* */的sql注释内容
|
||||||
@@ -76,10 +76,10 @@ public class SimpleDdlParser {
|
|||||||
if (result != null) {
|
if (result != null) {
|
||||||
result.setType(EventType.RENAME);
|
result.setType(EventType.RENAME);
|
||||||
|
|
||||||
String[] renameStrings = queryString.split(",");
|
String[] renameStrings = queryString.split(",");
|
||||||
if (renameStrings.length > 1){
|
if (renameStrings.length > 1) {
|
||||||
DdlResult lastResult = result;
|
DdlResult lastResult = result;
|
||||||
for (int i=1; i<renameStrings.length; i++){
|
for (int i = 1; i < renameStrings.length; i++) {
|
||||||
DdlResult ddlResult = parseRename(renameStrings[i], schmeaName, RENAME_REMNANT_PATTERN);
|
DdlResult ddlResult = parseRename(renameStrings[i], schmeaName, RENAME_REMNANT_PATTERN);
|
||||||
ddlResult.setType(EventType.RENAME);
|
ddlResult.setType(EventType.RENAME);
|
||||||
lastResult.setRenameTableResult(ddlResult);
|
lastResult.setRenameTableResult(ddlResult);
|
||||||
@@ -222,18 +222,16 @@ public class SimpleDdlParser {
|
|||||||
|
|
||||||
private String schemaName;
|
private String schemaName;
|
||||||
private String tableName;
|
private String tableName;
|
||||||
private String oriSchemaName; // rename ddl中的源表
|
private String oriSchemaName; // rename ddl中的源表
|
||||||
private String oriTableName; // rename ddl中的目标表
|
private String oriTableName; // rename ddl中的目标表
|
||||||
private EventType type;
|
private EventType type;
|
||||||
private DdlResult renameTableResult; // 多个rename table的存储
|
private DdlResult renameTableResult; // 多个rename table的存储
|
||||||
|
|
||||||
/*
|
/*
|
||||||
RENAME TABLE tbl_name TO new_tbl_name
|
* RENAME TABLE tbl_name TO new_tbl_name [, tbl_name2 TO new_tbl_name2]
|
||||||
[, tbl_name2 TO new_tbl_name2] ...
|
* ...
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public DdlResult(){
|
public DdlResult(){
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -305,14 +303,16 @@ public class SimpleDdlParser {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
DdlResult ddlResult = this;
|
DdlResult ddlResult = this;
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
do{
|
do {
|
||||||
sb.append(String.format("DdlResult [schemaName=%s , tableName=%s , oriSchemaName=%s , oriTableName=%s , type=%s ];",
|
sb.append(String.format("DdlResult [schemaName=%s , tableName=%s , oriSchemaName=%s , oriTableName=%s , type=%s ];",
|
||||||
ddlResult.schemaName, ddlResult.tableName, ddlResult.oriSchemaName, ddlResult.oriTableName, ddlResult.type));
|
ddlResult.schemaName,
|
||||||
|
ddlResult.tableName,
|
||||||
|
ddlResult.oriSchemaName,
|
||||||
|
ddlResult.oriTableName,
|
||||||
|
ddlResult.type));
|
||||||
ddlResult = ddlResult.renameTableResult;
|
ddlResult = ddlResult.renameTableResult;
|
||||||
}while (ddlResult!=null);
|
} while (ddlResult != null);
|
||||||
|
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user