use of org.apache.flink.sql.parser.ddl.SqlTableColumn.SqlRegularColumn in project flink by apache.
the class SqlCreateHiveTable method unparseColumns.
private void unparseColumns(HiveTableCreationContext context, SqlNodeList columns, SqlWriter writer, int leftPrec, int rightPrec) {
List<SqlHiveConstraintTrait> notNullTraits = context.notNullTraits;
int traitIndex = 0;
for (SqlNode node : columns) {
printIndent(writer);
SqlRegularColumn column = (SqlRegularColumn) node;
column.getName().unparse(writer, leftPrec, rightPrec);
writer.print(" ");
column.getType().unparse(writer, leftPrec, rightPrec);
if (column.getType().getNullable() != null && !column.getType().getNullable()) {
writer.keyword("NOT NULL");
notNullTraits.get(traitIndex++).unparse(writer, leftPrec, rightPrec);
}
column.getComment().ifPresent(c -> {
writer.keyword("COMMENT");
c.unparse(writer, leftPrec, rightPrec);
});
}
}
use of org.apache.flink.sql.parser.ddl.SqlTableColumn.SqlRegularColumn in project flink by apache.
the class OperationConverterUtils method toTableColumn.
private static TableColumn toTableColumn(SqlTableColumn tableColumn, SqlValidator sqlValidator) {
if (!(tableColumn instanceof SqlRegularColumn)) {
throw new TableException("Only regular columns are supported for this operation yet.");
}
SqlRegularColumn regularColumn = (SqlRegularColumn) tableColumn;
String name = regularColumn.getName().getSimple();
SqlDataTypeSpec typeSpec = regularColumn.getType();
boolean nullable = typeSpec.getNullable() == null ? true : typeSpec.getNullable();
LogicalType logicalType = FlinkTypeFactory.toLogicalType(typeSpec.deriveType(sqlValidator, nullable));
DataType dataType = TypeConversions.fromLogicalToDataType(logicalType);
return TableColumn.physical(name, dataType);
}
use of org.apache.flink.sql.parser.ddl.SqlTableColumn.SqlRegularColumn in project flink by apache.
the class SqlCreateTable method getFullConstraints.
/**
* Returns the column constraints plus the table constraints.
*/
public List<SqlTableConstraint> getFullConstraints() {
List<SqlTableConstraint> ret = new ArrayList<>();
this.columnList.forEach(column -> {
SqlTableColumn tableColumn = (SqlTableColumn) column;
if (tableColumn instanceof SqlRegularColumn) {
SqlRegularColumn regularColumn = (SqlRegularColumn) tableColumn;
regularColumn.getConstraint().map(ret::add);
}
});
ret.addAll(this.tableConstraints);
return ret;
}
Aggregations