Search in sources :

Example 1 with StreamlineParser

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

the class StreamlineSqlImpl method execute.

@Override
public void execute(Iterable<String> statements, ChannelHandler result) throws Exception {
    Map<String, DataSource> dataSources = new HashMap<>();
    for (String sql : statements) {
        StreamlineParser parser = new StreamlineParser(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 : StreamlineParser(com.hortonworks.streamline.streams.sql.parser.StreamlineParser) HashMap(java.util.HashMap) AbstractValuesProcessor(com.hortonworks.streamline.streams.sql.runtime.AbstractValuesProcessor) SqlCreateTable(com.hortonworks.streamline.streams.sql.parser.SqlCreateTable) DataSource(com.hortonworks.streamline.streams.sql.runtime.DataSource) PlanCompiler(com.hortonworks.streamline.streams.sql.compiler.PlanCompiler) RelNode(org.apache.calcite.rel.RelNode) SqlCreateFunction(com.hortonworks.streamline.streams.sql.parser.SqlCreateFunction) Planner(org.apache.calcite.tools.Planner) FrameworkConfig(org.apache.calcite.tools.FrameworkConfig) SqlNode(org.apache.calcite.sql.SqlNode)

Aggregations

PlanCompiler (com.hortonworks.streamline.streams.sql.compiler.PlanCompiler)1 SqlCreateFunction (com.hortonworks.streamline.streams.sql.parser.SqlCreateFunction)1 SqlCreateTable (com.hortonworks.streamline.streams.sql.parser.SqlCreateTable)1 StreamlineParser (com.hortonworks.streamline.streams.sql.parser.StreamlineParser)1 AbstractValuesProcessor (com.hortonworks.streamline.streams.sql.runtime.AbstractValuesProcessor)1 DataSource (com.hortonworks.streamline.streams.sql.runtime.DataSource)1 HashMap (java.util.HashMap)1 RelNode (org.apache.calcite.rel.RelNode)1 SqlNode (org.apache.calcite.sql.SqlNode)1 FrameworkConfig (org.apache.calcite.tools.FrameworkConfig)1 Planner (org.apache.calcite.tools.Planner)1