Search in sources :

Example 6 with SqlCreateTable

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

the class StormSqlImpl method submit.

@Override
public void submit(String name, Iterable<String> statements, Map<String, Object> topoConf, SubmitOptions opts, StormSubmitter.ProgressListener progressListener, String asUser) throws Exception {
    for (String sql : statements) {
        StormParser parser = new StormParser(sql);
        SqlNode node = parser.impl().parseSqlStmtEof();
        if (node instanceof SqlCreateTable) {
            sqlContext.interpretCreateTable((SqlCreateTable) node);
        } else if (node instanceof SqlCreateFunction) {
            sqlContext.interpretCreateFunction((SqlCreateFunction) node);
        } else {
            AbstractStreamsProcessor processor = sqlContext.compileSql(sql);
            StormTopology topo = processor.build();
            Path jarPath = null;
            try {
                // QueryPlanner on Streams mode configures the topology with compiled classes,
                // so we need to add new classes into topology jar
                // Topology will be serialized and sent to Nimbus, and deserialized and executed in workers.
                jarPath = Files.createTempFile("storm-sql", ".jar");
                System.setProperty("storm.jar", jarPath.toString());
                packageTopology(jarPath, processor);
                StormSubmitter.submitTopologyAs(name, topoConf, topo, opts, progressListener, asUser);
            } finally {
                if (jarPath != null) {
                    Files.delete(jarPath);
                }
            }
        }
    }
}
Also used : Path(java.nio.file.Path) StormTopology(org.apache.storm.generated.StormTopology) SqlCreateFunction(org.apache.storm.sql.parser.SqlCreateFunction) StormParser(org.apache.storm.sql.parser.StormParser) SqlCreateTable(org.apache.storm.sql.parser.SqlCreateTable) SqlNode(org.apache.calcite.sql.SqlNode)

Example 7 with SqlCreateTable

use of org.apache.storm.sql.parser.SqlCreateTable 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

SqlCreateTable (org.apache.storm.sql.parser.SqlCreateTable)7 SqlNode (org.apache.calcite.sql.SqlNode)5 SqlCreateFunction (org.apache.storm.sql.parser.SqlCreateFunction)5 StormParser (org.apache.storm.sql.parser.StormParser)5 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 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 StormTopology (org.apache.storm.generated.StormTopology)2 ColumnConstraint (org.apache.storm.sql.parser.ColumnConstraint)2 ColumnDefinition (org.apache.storm.sql.parser.ColumnDefinition)2 QueryPlanner (org.apache.storm.sql.planner.trident.QueryPlanner)2 FieldInfo (org.apache.storm.sql.runtime.FieldInfo)2 ISqlTridentDataSource (org.apache.storm.sql.runtime.ISqlTridentDataSource)2 RelNode (org.apache.calcite.rel.RelNode)1 FrameworkConfig (org.apache.calcite.tools.FrameworkConfig)1