Search in sources :

Example 1 with StormParser

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

the class StormSqlImpl method explain.

@Override
public void explain(Iterable<String> statements) throws Exception {
    Map<String, ISqlTridentDataSource> dataSources = new HashMap<>();
    for (String sql : statements) {
        StormParser parser = new StormParser(sql);
        SqlNode node = parser.impl().parseSqlStmtEof();
        System.out.println("===========================================================");
        System.out.println("query>");
        System.out.println(sql);
        System.out.println("-----------------------------------------------------------");
        if (node instanceof SqlCreateTable) {
            handleCreateTableForTrident((SqlCreateTable) node, dataSources);
            System.out.println("No plan presented on DDL");
        } else if (node instanceof SqlCreateFunction) {
            handleCreateFunction((SqlCreateFunction) node);
            System.out.println("No plan presented on DDL");
        } else {
            FrameworkConfig config = buildFrameWorkConfig();
            Planner planner = Frameworks.getPlanner(config);
            SqlNode parse = planner.parse(sql);
            SqlNode validate = planner.validate(parse);
            RelNode tree = planner.convert(validate);
            String plan = StormRelUtils.explain(tree, SqlExplainLevel.ALL_ATTRIBUTES);
            System.out.println("plan>");
            System.out.println(plan);
        }
        System.out.println("===========================================================");
    }
}
Also used : RelNode(org.apache.calcite.rel.RelNode) HashMap(java.util.HashMap) SqlCreateFunction(org.apache.storm.sql.parser.SqlCreateFunction) ISqlTridentDataSource(org.apache.storm.sql.runtime.ISqlTridentDataSource) Planner(org.apache.calcite.tools.Planner) QueryPlanner(org.apache.storm.sql.planner.trident.QueryPlanner) FrameworkConfig(org.apache.calcite.tools.FrameworkConfig) StormParser(org.apache.storm.sql.parser.StormParser) SqlCreateTable(org.apache.storm.sql.parser.SqlCreateTable) SqlNode(org.apache.calcite.sql.SqlNode)

Example 2 with StormParser

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

the class StormSqlImpl method submit.

@Override
public void submit(String name, Iterable<String> statements, Map<String, ?> stormConf, SubmitOptions opts, StormSubmitter.ProgressListener progressListener, String asUser) throws Exception {
    Map<String, ISqlTridentDataSource> dataSources = new HashMap<>();
    for (String sql : statements) {
        StormParser parser = new StormParser(sql);
        SqlNode node = parser.impl().parseSqlStmtEof();
        if (node instanceof SqlCreateTable) {
            handleCreateTableForTrident((SqlCreateTable) node, dataSources);
        } else if (node instanceof SqlCreateFunction) {
            handleCreateFunction((SqlCreateFunction) node);
        } else {
            QueryPlanner planner = new QueryPlanner(schema);
            AbstractTridentProcessor processor = planner.compile(dataSources, sql);
            TridentTopology topo = processor.build();
            Path jarPath = null;
            try {
                // QueryPlanner on Trident 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, stormConf, topo.build(), opts, progressListener, asUser);
            } finally {
                if (jarPath != null) {
                    Files.delete(jarPath);
                }
            }
        }
    }
}
Also used : Path(java.nio.file.Path) HashMap(java.util.HashMap) TridentTopology(org.apache.storm.trident.TridentTopology) SqlCreateFunction(org.apache.storm.sql.parser.SqlCreateFunction) ISqlTridentDataSource(org.apache.storm.sql.runtime.ISqlTridentDataSource) StormParser(org.apache.storm.sql.parser.StormParser) SqlCreateTable(org.apache.storm.sql.parser.SqlCreateTable) QueryPlanner(org.apache.storm.sql.planner.trident.QueryPlanner) SqlNode(org.apache.calcite.sql.SqlNode)

Example 3 with StormParser

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

the class StormSqlImpl method execute.

@Override
public void execute(Iterable<String> statements, ChannelHandler result) throws Exception {
    Map<String, DataSource> dataSources = new HashMap<>();
    for (String sql : statements) {
        StormParser parser = new StormParser(sql);
        SqlNode node = parser.impl().parseSqlStmtEof();
        if (node instanceof SqlCreateTable) {
            handleCreateTable((SqlCreateTable) node, dataSources);
        } else if (node instanceof SqlCreateFunction) {
            handleCreateFunction((SqlCreateFunction) node);
        } else {
            FrameworkConfig config = buildFrameWorkConfig();
            Planner planner = Frameworks.getPlanner(config);
            SqlNode parse = planner.parse(sql);
            SqlNode validate = planner.validate(parse);
            RelNode tree = planner.convert(validate);
            PlanCompiler compiler = new PlanCompiler(typeFactory);
            AbstractValuesProcessor proc = compiler.compile(tree);
            proc.initialize(dataSources, result);
        }
    }
}
Also used : HashMap(java.util.HashMap) AbstractValuesProcessor(org.apache.storm.sql.runtime.AbstractValuesProcessor) SqlCreateTable(org.apache.storm.sql.parser.SqlCreateTable) ISqlTridentDataSource(org.apache.storm.sql.runtime.ISqlTridentDataSource) DataSource(org.apache.storm.sql.runtime.DataSource) PlanCompiler(org.apache.storm.sql.compiler.backends.standalone.PlanCompiler) RelNode(org.apache.calcite.rel.RelNode) SqlCreateFunction(org.apache.storm.sql.parser.SqlCreateFunction) Planner(org.apache.calcite.tools.Planner) QueryPlanner(org.apache.storm.sql.planner.trident.QueryPlanner) FrameworkConfig(org.apache.calcite.tools.FrameworkConfig) StormParser(org.apache.storm.sql.parser.StormParser) SqlNode(org.apache.calcite.sql.SqlNode)

Aggregations

HashMap (java.util.HashMap)3 SqlNode (org.apache.calcite.sql.SqlNode)3 SqlCreateFunction (org.apache.storm.sql.parser.SqlCreateFunction)3 SqlCreateTable (org.apache.storm.sql.parser.SqlCreateTable)3 StormParser (org.apache.storm.sql.parser.StormParser)3 QueryPlanner (org.apache.storm.sql.planner.trident.QueryPlanner)3 ISqlTridentDataSource (org.apache.storm.sql.runtime.ISqlTridentDataSource)3 RelNode (org.apache.calcite.rel.RelNode)2 FrameworkConfig (org.apache.calcite.tools.FrameworkConfig)2 Planner (org.apache.calcite.tools.Planner)2 Path (java.nio.file.Path)1 PlanCompiler (org.apache.storm.sql.compiler.backends.standalone.PlanCompiler)1 AbstractValuesProcessor (org.apache.storm.sql.runtime.AbstractValuesProcessor)1 DataSource (org.apache.storm.sql.runtime.DataSource)1 TridentTopology (org.apache.storm.trident.TridentTopology)1