Search in sources :

Example 6 with SqlCreateFunction

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

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

the class StormSqlContext method interpretCreateFunction.

public void interpretCreateFunction(SqlCreateFunction sqlCreateFunction) throws ClassNotFoundException {
    if (sqlCreateFunction.jarName() != null) {
        throw new UnsupportedOperationException("UDF 'USING JAR' not implemented");
    }
    Method method;
    Function function;
    if ((method = findMethod(sqlCreateFunction.className(), "evaluate")) != null) {
        function = ScalarFunctionImpl.create(method);
    } else if (findMethod(sqlCreateFunction.className(), "add") != null) {
        function = AggregateFunctionImpl.create(Class.forName(sqlCreateFunction.className()));
    } else {
        throw new RuntimeException("Invalid scalar or aggregate function");
    }
    schema.add(sqlCreateFunction.functionName().toUpperCase(), function);
    hasUdf = true;
}
Also used : Function(org.apache.calcite.schema.Function) SqlCreateFunction(org.apache.storm.sql.parser.SqlCreateFunction) Method(java.lang.reflect.Method)

Aggregations

SqlCreateFunction (org.apache.storm.sql.parser.SqlCreateFunction)7 SqlNode (org.apache.calcite.sql.SqlNode)5 SqlCreateTable (org.apache.storm.sql.parser.SqlCreateTable)5 StormParser (org.apache.storm.sql.parser.StormParser)5 Method (java.lang.reflect.Method)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 Function (org.apache.calcite.schema.Function)2 StormTopology (org.apache.storm.generated.StormTopology)2 QueryPlanner (org.apache.storm.sql.planner.trident.QueryPlanner)2 ISqlTridentDataSource (org.apache.storm.sql.runtime.ISqlTridentDataSource)2 RelNode (org.apache.calcite.rel.RelNode)1 FrameworkConfig (org.apache.calcite.tools.FrameworkConfig)1 Planner (org.apache.calcite.tools.Planner)1 Config (org.apache.storm.Config)1 PlanCompiler (org.apache.storm.sql.compiler.backends.standalone.PlanCompiler)1 CompilingClassLoader (org.apache.storm.sql.javac.CompilingClassLoader)1 AbstractValuesProcessor (org.apache.storm.sql.runtime.AbstractValuesProcessor)1 DataSource (org.apache.storm.sql.runtime.DataSource)1 TridentTopology (org.apache.storm.trident.TridentTopology)1