Search in sources :

Example 1 with ColumnConstraint

use of com.hortonworks.streamline.streams.sql.parser.ColumnConstraint in project streamline by hortonworks.

the class StreamlineSqlImpl method updateSchema.

private List<FieldInfo> updateSchema(SqlCreateTable n) {
    CompilerUtil.TableBuilderInfo builder = new CompilerUtil.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 : CompilerUtil(com.hortonworks.streamline.streams.sql.compiler.CompilerUtil) SqlCreateTable(com.hortonworks.streamline.streams.sql.parser.SqlCreateTable) SqlOperatorTable(org.apache.calcite.sql.SqlOperatorTable) Table(org.apache.calcite.schema.Table) ChainedSqlOperatorTable(org.apache.calcite.sql.util.ChainedSqlOperatorTable) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) ArrayList(java.util.ArrayList) RelDataType(org.apache.calcite.rel.type.RelDataType) ColumnDefinition(com.hortonworks.streamline.streams.sql.parser.ColumnDefinition) ColumnConstraint(com.hortonworks.streamline.streams.sql.parser.ColumnConstraint) FieldInfo(com.hortonworks.streamline.streams.sql.runtime.FieldInfo)

Aggregations

CompilerUtil (com.hortonworks.streamline.streams.sql.compiler.CompilerUtil)1 ColumnConstraint (com.hortonworks.streamline.streams.sql.parser.ColumnConstraint)1 ColumnDefinition (com.hortonworks.streamline.streams.sql.parser.ColumnDefinition)1 SqlCreateTable (com.hortonworks.streamline.streams.sql.parser.SqlCreateTable)1 FieldInfo (com.hortonworks.streamline.streams.sql.runtime.FieldInfo)1 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