in fastmodel-transform/fastmodel-transform-starrocks/src/main/java/com/aliyun/fastmodel/transform/starrocks/format/StarRocksOutVisitor.java [169:213]
protected String formatColumnDefinition(ColumnDefinition column, Integer max) {
BaseDataType dataType = column.getDataType();
String col = formatColName(column.getColName(), max);
StringBuilder sb = new StringBuilder().append(col);
if (dataType != null) {
sb.append(" ").append(formatDataType(dataType));
}
List<Property> columnProperties = column.getColumnProperties();
//charset
String charSet = PropertyUtil.getPropertyValue(columnProperties, StarRocksPropertyKey.COLUMN_CHAR_SET.getValue());
if (StringUtils.isNotBlank(charSet)) {
sb.append(" ").append("CHARSET ").append(charSet);
}
//key
String key = PropertyUtil.getPropertyValue(columnProperties, COLUMN_KEY.getValue());
if (StringUtils.isNotBlank(key)) {
sb.append(" ").append("KEY");
}
//aggDesc
String propertyValue = PropertyUtil.getPropertyValue(columnProperties, COLUMN_AGG_DESC.getValue());
if (StringUtils.isNotBlank(propertyValue)) {
sb.append(" ").append(propertyValue);
}
boolean isNotNull = column.getNotNull() != null && column.getNotNull();
if (isNotNull) {
sb.append(" NOT NULL");
} else if (BooleanUtils.isFalse(column.getNotNull())) {
sb.append(" NULL");
}
if (column.getDefaultValue() != null) {
String expressionValue = formatExpression(column.getDefaultValue());
if (column.getDefaultValue() instanceof FunctionCall) {
sb.append(" DEFAULT (").append(expressionValue).append(")");
} else {
sb.append(" DEFAULT ").append(expressionValue);
}
}
//auto increment
String autoIncrement = PropertyUtil.getPropertyValue(columnProperties, COLUMN_AUTO_INCREMENT.getValue());
if (StringUtils.equalsIgnoreCase(BooleanLiteral.TRUE, autoIncrement)) {
sb.append(" ").append("AUTO_INCREMENT");
}
sb.append(formatComment(column.getComment(), isEndNewLine(sb.toString())));
return sb.toString();
}