Search in sources :

Example 6 with FieldInfo

use of org.apache.storm.sql.runtime.FieldInfo in project storm by apache.

the class StormSqlContext method interpretCreateTable.

public void interpretCreateTable(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);
    ISqlStreamsDataSource ds = DataSourcesRegistry.constructStreamsDataSource(n.location(), n.inputFormatClass(), n.outputFormatClass(), n.properties(), fields);
    if (ds == null) {
        throw new RuntimeException("Failed to find data source for " + n.tableName() + " URI: " + n.location());
    } else if (dataSources.containsKey(n.tableName())) {
        throw new RuntimeException("Duplicated definition for table " + n.tableName());
    }
    dataSources.put(n.tableName(), ds);
}
Also used : CompilerUtil(org.apache.storm.sql.compiler.CompilerUtil) 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) SqlCreateTable(org.apache.storm.sql.parser.SqlCreateTable) ArrayList(java.util.ArrayList) RelDataType(org.apache.calcite.rel.type.RelDataType) ColumnDefinition(org.apache.storm.sql.parser.ColumnDefinition) ISqlStreamsDataSource(org.apache.storm.sql.runtime.ISqlStreamsDataSource) ColumnConstraint(org.apache.storm.sql.parser.ColumnConstraint) FieldInfo(org.apache.storm.sql.runtime.FieldInfo)

Aggregations

FieldInfo (org.apache.storm.sql.runtime.FieldInfo)6 ArrayList (java.util.ArrayList)4 RelDataType (org.apache.calcite.rel.type.RelDataType)2 Table (org.apache.calcite.schema.Table)2 SqlOperatorTable (org.apache.calcite.sql.SqlOperatorTable)2 SqlStdOperatorTable (org.apache.calcite.sql.fun.SqlStdOperatorTable)2 ChainedSqlOperatorTable (org.apache.calcite.sql.util.ChainedSqlOperatorTable)2 Scheme (org.apache.storm.spout.Scheme)2 ColumnConstraint (org.apache.storm.sql.parser.ColumnConstraint)2 ColumnDefinition (org.apache.storm.sql.parser.ColumnDefinition)2 SqlCreateTable (org.apache.storm.sql.parser.SqlCreateTable)2 IOutputSerializer (org.apache.storm.sql.runtime.IOutputSerializer)2 ISqlTridentDataSource (org.apache.storm.sql.runtime.ISqlTridentDataSource)2 ByteBuffer (java.nio.ByteBuffer)1 ByteBufferDeserializer (org.apache.kafka.common.serialization.ByteBufferDeserializer)1 ZkHosts (org.apache.storm.kafka.ZkHosts)1 KafkaSpoutConfig (org.apache.storm.kafka.spout.KafkaSpoutConfig)1 TridentKafkaConfig (org.apache.storm.kafka.trident.TridentKafkaConfig)1 SchemeAsMultiScheme (org.apache.storm.spout.SchemeAsMultiScheme)1 CompilerUtil (org.apache.storm.sql.compiler.CompilerUtil)1