Search in sources :

Example 1 with ColumnConstraint

use of org.apache.storm.sql.parser.ColumnConstraint in project storm by apache.

the class StormSqlImpl method updateSchema.

private List<FieldInfo> updateSchema(SqlCreateTable n) {
    TableBuilderInfo builder = new TableBuilderInfo(typeFactory);
    List<FieldInfo> fields = new ArrayList<>();
    for (ColumnDefinition col : n.fieldList()) {
        builder.field(col.name(), col.type(), col.constraint());
        RelDataType dataType = col.type().deriveType(typeFactory);
        Class<?> javaType = (Class<?>) typeFactory.getJavaClass(dataType);
        ColumnConstraint constraint = col.constraint();
        boolean isPrimary = constraint != null && constraint instanceof ColumnConstraint.PrimaryKey;
        fields.add(new FieldInfo(col.name(), javaType, isPrimary));
    }
    if (n.parallelism() != null) {
        builder.parallelismHint(n.parallelism());
    }
    Table table = builder.build();
    schema.add(n.tableName(), table);
    return fields;
}
Also used : Table(org.apache.calcite.schema.Table) ChainedSqlOperatorTable(org.apache.calcite.sql.util.ChainedSqlOperatorTable) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) SqlCreateTable(org.apache.storm.sql.parser.SqlCreateTable) SqlOperatorTable(org.apache.calcite.sql.SqlOperatorTable) TableBuilderInfo(org.apache.storm.sql.compiler.CompilerUtil.TableBuilderInfo) ColumnConstraint(org.apache.storm.sql.parser.ColumnConstraint) ArrayList(java.util.ArrayList) RelDataType(org.apache.calcite.rel.type.RelDataType) FieldInfo(org.apache.storm.sql.runtime.FieldInfo) ColumnDefinition(org.apache.storm.sql.parser.ColumnDefinition)

Aggregations

ArrayList (java.util.ArrayList)1 RelDataType (org.apache.calcite.rel.type.RelDataType)1 Table (org.apache.calcite.schema.Table)1 SqlOperatorTable (org.apache.calcite.sql.SqlOperatorTable)1 SqlStdOperatorTable (org.apache.calcite.sql.fun.SqlStdOperatorTable)1 ChainedSqlOperatorTable (org.apache.calcite.sql.util.ChainedSqlOperatorTable)1 TableBuilderInfo (org.apache.storm.sql.compiler.CompilerUtil.TableBuilderInfo)1 ColumnConstraint (org.apache.storm.sql.parser.ColumnConstraint)1 ColumnDefinition (org.apache.storm.sql.parser.ColumnDefinition)1 SqlCreateTable (org.apache.storm.sql.parser.SqlCreateTable)1 FieldInfo (org.apache.storm.sql.runtime.FieldInfo)1