in holo-shipper/src/main/java/com/alibaba/hologres/shipper/HoloDBShipper.java [221:275]
public String rectifyDDL(String tableName, String tableDDL, boolean restoreOwner){
String quotedTableName = HoloUtils.getTableNameWithQuotes(tableName);
tableDDL = tableDDL.replace(tableName, quotedTableName);
String sinkTableName = HoloUtils.getTableNameWithQuotes(getSinkTableName(tableName));
tableDDL = tableDDL.replace(quotedTableName, sinkTableName);
if(parentMapping.containsKey(tableName)) {
String parentName = parentMapping.get(tableName);
String quotedParentName = HoloUtils.getTableNameWithQuotes(parentName);
tableDDL = tableDDL.replace(parentName, quotedParentName);
String sinkParentName = HoloUtils.getTableNameWithQuotes(getSinkTableName(parentName));
tableDDL = tableDDL.replace(quotedParentName, sinkParentName);
}
String rectifiedDDL = "";
for(String line: tableDDL.split("\n")) {
if(line.contains("OWNER TO")) {
if(restoreOwner) {
rectifiedDDL = rectifiedDDL + line + "\n";
}
}
else if(line.startsWith(("-- DEPENDANTS"))) {
rectifiedDDL = rectifiedDDL+"END;\n";
break;
}
else if (line.startsWith("CALL") && line.contains("'orientation'") && line.contains("''"))
rectifiedDDL = rectifiedDDL + "-- " + line + "\n";
else if ((line.startsWith("CALL") && line.contains("'table_group'")) || (line.startsWith("table_group ="))) { //不对table group进行设置
int endIndex = line.lastIndexOf("'");
int startIndex = line.lastIndexOf("'", endIndex-1) + 1;
String srcTG = line.substring(startIndex, endIndex);
String dstTG = getSinkTableGroupName(srcTG);
if (dstTG != null)
rectifiedDDL = rectifiedDDL + line.replaceAll(srcTG, dstTG) + "\n";
else
rectifiedDDL = rectifiedDDL + "-- " + line + "\n";
} else if (line.startsWith("CREATE TABLE") && line.contains("PARTITION OF")){
int startIndex = line.lastIndexOf("PARTITION OF ") + 13;
String parentTableName = line.substring(startIndex);
if(parentMapping.containsKey(tableName)) {
String parentName = parentMapping.get(tableName);
String sinkParentName = HoloUtils.getTableNameWithQuotes(getSinkTableName(parentName));
String pureParentTableName = parentName.split("\\.", 2)[1];
if (!parentTableName.contains(".") && parentTableName.equalsIgnoreCase(pureParentTableName)) {
line = line.replace("PARTITION OF " + pureParentTableName, "PARTITION OF " + sinkParentName);
}
}
rectifiedDDL = rectifiedDDL+line+"\n";
}
else if (line.startsWith("CALL") && line.contains("'colocate_with'")) //0.8时期colocate_with用法会引起引擎不兼容等问题
rectifiedDDL = rectifiedDDL + "-- " + line + "\n";
else
rectifiedDDL = rectifiedDDL+line+"\n";
}
LOGGER.info("rectifiedDDL {}",rectifiedDDL);
return rectifiedDDL;
}