Search in sources :

Example 6 with AbstractValuesProcessor

use of com.hortonworks.streamline.streams.sql.runtime.AbstractValuesProcessor 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

AbstractValuesProcessor (com.hortonworks.streamline.streams.sql.runtime.AbstractValuesProcessor)6 PlanCompiler (com.hortonworks.streamline.streams.sql.compiler.PlanCompiler)5 DataSource (com.hortonworks.streamline.streams.sql.runtime.DataSource)5 HashMap (java.util.HashMap)5 ChannelHandler (com.hortonworks.streamline.streams.sql.runtime.ChannelHandler)4 CorrelatedValues (com.hortonworks.streamline.streams.sql.runtime.CorrelatedValues)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 ImmutableMap (com.google.common.collect.ImmutableMap)1 CompilingClassLoader (com.hortonworks.streamline.streams.sql.compiler.javac.CompilingClassLoader)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 Map (java.util.Map)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