in fastmodel-transform/fastmodel-transform-flink/src/main/java/com/aliyun/fastmodel/transform/flink/format/FlinkOutVisitor.java [46:109]
public Boolean visitCreateTable(CreateTable node, Integer indent) {
builder.append("CREATE TABLE ");
if (node.isNotExists()) {
builder.append("IF NOT EXISTS ");
}
String tableName = getCode(node.getQualifiedName());
builder.append(tableName);
boolean columnEmpty = node.isColumnEmpty();
if (!columnEmpty) {
builder.append("\n(\n");
String elementIndent = indentString(indent + 1);
String columnList = formatColumnList(node.getColumnDefines(), elementIndent);
builder.append(columnList);
// constraint
List<BaseConstraint> constraints = node.getConstraintStatements();
if (CollectionUtils.isNotEmpty(constraints)) {
// watermark definition
Optional<BaseConstraint> waterMarkConstraintOpt = constraints.stream()
.filter(constraint -> constraint instanceof WaterMarkConstraint).findAny();
waterMarkConstraintOpt.ifPresent(constraint -> builder.append(",\n").append(elementIndent).append(formatWaterMarkConstraint((WaterMarkConstraint) constraint, indent)));
// primary key
Optional<BaseConstraint> primaryConstraint = constraints.stream()
.filter(constraint -> constraint instanceof PrimaryConstraint).findAny();
primaryConstraint.ifPresent(constraint -> {
builder.append(",\n").append(elementIndent);
process(constraint, indent);
});
}
builder.append("\n").append(")");
}
if (node.getComment() != null) {
builder.append("\n");
builder.append(formatComment(node.getComment(), true));
}
// partitioned by
if (!node.isPartitionEmpty()) {
builder.append("\n");
process(node.getPartitionedBy(), indent);
} else {
String propertyValue = PropertyUtil.getPropertyValue(node.getProperties(), TABLE_PARTITION_RAW.getValue());
if (StringUtils.isNotBlank(propertyValue)) {
builder.append("\n");
builder.append(propertyValue);
}
}
if (!node.isPropertyEmpty()) {
String prop = formatProperty(node.getProperties());
if (StringUtils.isNotBlank(prop)) {
builder.append("\n");
builder.append("WITH (");
builder.append(prop);
builder.append(")");
}
}
builder.append(";");
//不支持没有列的表
return !columnEmpty;
}