use of org.apache.flink.sql.parser.ddl.SqlTableColumn.SqlComputedColumn in project flink by apache.
the class SqlCreateTable method getColumnSqlString.
/**
* Returns the projection format of the DDL columns(including computed columns). i.e. the
* following DDL:
*
* <pre>
* create table tbl1(
* col1 int,
* col2 varchar,
* col3 as to_timestamp(col2)
* ) with (
* 'connector' = 'csv'
* )
* </pre>
*
* <p>is equivalent with query "col1, col2, to_timestamp(col2) as col3", caution that the
* "computed column" operands have been reversed.
*/
public String getColumnSqlString() {
SqlPrettyWriter writer = new SqlPrettyWriter(SqlPrettyWriter.config().withDialect(AnsiSqlDialect.DEFAULT).withAlwaysUseParentheses(true).withSelectListItemsOnSeparateLines(false).withIndentation(0));
writer.startList("", "");
for (SqlNode column : columnList) {
writer.sep(",");
SqlTableColumn tableColumn = (SqlTableColumn) column;
if (tableColumn instanceof SqlComputedColumn) {
SqlComputedColumn computedColumn = (SqlComputedColumn) tableColumn;
computedColumn.getExpr().unparse(writer, 0, 0);
writer.keyword("AS");
}
tableColumn.getName().unparse(writer, 0, 0);
}
return writer.toString();
}
Aggregations