Search in sources :

Example 1 with SqlRegularColumn

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);
        });
    }
}
Also used : SqlRegularColumn(org.apache.flink.sql.parser.ddl.SqlTableColumn.SqlRegularColumn) SqlTableConstraint(org.apache.flink.sql.parser.ddl.constraint.SqlTableConstraint) SqlNode(org.apache.calcite.sql.SqlNode)

Example 2 with SqlRegularColumn

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);
}
Also used : TableException(org.apache.flink.table.api.TableException) SqlRegularColumn(org.apache.flink.sql.parser.ddl.SqlTableColumn.SqlRegularColumn) LogicalType(org.apache.flink.table.types.logical.LogicalType) DataType(org.apache.flink.table.types.DataType) SqlDataTypeSpec(org.apache.calcite.sql.SqlDataTypeSpec)

Example 3 with SqlRegularColumn

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;
}
Also used : SqlRegularColumn(org.apache.flink.sql.parser.ddl.SqlTableColumn.SqlRegularColumn) ArrayList(java.util.ArrayList) SqlTableConstraint(org.apache.flink.sql.parser.ddl.constraint.SqlTableConstraint)

Aggregations

SqlRegularColumn (org.apache.flink.sql.parser.ddl.SqlTableColumn.SqlRegularColumn)3 SqlTableConstraint (org.apache.flink.sql.parser.ddl.constraint.SqlTableConstraint)2 ArrayList (java.util.ArrayList)1 SqlDataTypeSpec (org.apache.calcite.sql.SqlDataTypeSpec)1 SqlNode (org.apache.calcite.sql.SqlNode)1 TableException (org.apache.flink.table.api.TableException)1 DataType (org.apache.flink.table.types.DataType)1 LogicalType (org.apache.flink.table.types.logical.LogicalType)1