in fastmodel-transform/fastmodel-transform-adbmysql/src/main/java/com/aliyun/fastmodel/transform/adbmysql/format/AdbMysqlOutVisitor.java [74:148]
public Boolean visitCreateTable(CreateTable node, Integer indent) {
boolean columnEmpty = node.isColumnEmpty();
//maxcompute不支持没有列的表
boolean executable = !columnEmpty;
builder.append(formatCreateTable(node));
if (node.isNotExists()) {
builder.append("IF NOT EXISTS ");
}
String tableName = getCode(node.getQualifiedName());
builder.append(tableName);
if (!columnEmpty) {
builder.append("\n(\n");
String elementIndent = indentString(indent + 1);
String columnList = formatColumnList(node.getColumnDefines(), elementIndent);
builder.append(columnList);
if (!node.isConstraintEmpty()) {
appendConstraint(node, indent);
}
if (!node.isIndexEmpty()) {
Iterator<TableIndex> iterator = node.getTableIndexList().iterator();
while (iterator.hasNext()) {
builder.append(",\n");
process(iterator.next(), indent + 1);
}
}
builder.append("\n").append(")");
} else {
if (!node.isCommentElementEmpty()) {
builder.append(newLine("/*("));
String elementIndent = indentString(indent + 1);
builder.append(formatCommentElement(node.getColumnCommentElements(), elementIndent));
builder.append(newLine(")*/"));
}
}
if (!node.isConstraintEmpty()) {
List<BaseConstraint> nonKeyConstraint = node.getConstraintStatements().stream().filter(
c -> c instanceof NonKeyConstraint).collect(Collectors.toList());
appendConstraint(nonKeyConstraint, indent);
}
//分区信息内容
if (!node.isPartitionEmpty()) {
if (node.getPartitionedBy() instanceof ExpressionPartitionBy) {
ExpressionPartitionBy expressionPartitionBy = (ExpressionPartitionBy)node.getPartitionedBy();
process(expressionPartitionBy);
} else {
String list = formatPartitions(node.getPartitionedBy().getColumnDefinitions());
if (!isEndNewLine(builder.toString())) {
builder.append(StringUtils.LF);
}
builder.append(list);
}
} else {
String propertyValue = PropertyUtil.getPropertyValue(node.getProperties(), TABLE_PARTITION_RAW.getValue());
if (StringUtils.isNotBlank(propertyValue)) {
if (!isEndNewLine(builder.toString())) {
builder.append("\n");
}
builder.append(propertyValue);
}
}
appendLifecycle(node);
//storage policy
appendProperty(node);
//external table property
appendExternalTable(node);
//append comment
if (node.getComment() != null) {
if (!isEndNewLine(builder.toString())) {
builder.append(StringUtils.LF);
}
builder.append(formatComment(node.getComment(), true));
}
return executable;
}