Search in sources :

Example 6 with CompilingClassLoader

use of org.apache.storm.sql.javac.CompilingClassLoader in project storm by apache.

the class QueryPlanner method compile.

public AbstractStreamsProcessor compile(Map<String, ISqlStreamsDataSource> sources, String query) throws Exception {
    StreamsRel relNode = getPlan(query);
    StreamsPlanCreator streamsPlanCreator = new StreamsPlanCreator(sources, new RexBuilder(typeFactory));
    relNode.streamsPlan(streamsPlanCreator);
    final StreamBuilder streamBuilder = streamsPlanCreator.getStreamBuilder();
    final Stream<Values> lastStream = streamsPlanCreator.pop();
    final DataContext dc = streamsPlanCreator.getDataContext();
    final List<CompilingClassLoader> cls = streamsPlanCreator.getClassLoaders();
    return new AbstractStreamsProcessor() {

        @Override
        public StormTopology build() {
            return streamBuilder.build();
        }

        @Override
        public Stream<Values> outputStream() {
            return lastStream;
        }

        @Override
        public DataContext getDataContext() {
            return dc;
        }

        @Override
        public List<CompilingClassLoader> getClassLoaders() {
            return cls;
        }
    };
}
Also used : DataContext(org.apache.calcite.DataContext) AbstractStreamsProcessor(org.apache.storm.sql.AbstractStreamsProcessor) CompilingClassLoader(org.apache.storm.sql.javac.CompilingClassLoader) Values(org.apache.storm.tuple.Values) RexBuilder(org.apache.calcite.rex.RexBuilder) StreamsRel(org.apache.storm.sql.planner.streams.rel.StreamsRel) StreamBuilder(org.apache.storm.streams.StreamBuilder)

Example 7 with CompilingClassLoader

use of org.apache.storm.sql.javac.CompilingClassLoader in project storm by apache.

the class StormSqlLocalClusterImpl method runLocal.

public void runLocal(LocalCluster localCluster, Iterable<String> statements, Predicate<Void> waitCondition, long waitTimeoutMs) throws Exception {
    final Config conf = new Config();
    conf.setMaxSpoutPending(20);
    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();
            if (processor.getClassLoaders() != null && processor.getClassLoaders().size() > 0) {
                CompilingClassLoader lastClassloader = processor.getClassLoaders().get(processor.getClassLoaders().size() - 1);
                Utils.setClassLoaderForJavaDeSerialize(lastClassloader);
            }
            try (LocalCluster.LocalTopology stormTopo = localCluster.submitTopology("storm-sql", conf, topo)) {
                waitForCompletion(waitTimeoutMs, waitCondition);
            } finally {
                while (localCluster.getTopologySummaries().size() > 0) {
                    Thread.sleep(10);
                }
                Utils.resetClassLoaderForJavaDeSerialize();
            }
        }
    }
}
Also used : CompilingClassLoader(org.apache.storm.sql.javac.CompilingClassLoader) Config(org.apache.storm.Config) 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 8 with CompilingClassLoader

use of org.apache.storm.sql.javac.CompilingClassLoader in project storm by apache.

the class StormSqlImpl method packageTopology.

private void packageTopology(Path jar, AbstractTridentProcessor processor) throws IOException {
    Manifest manifest = new Manifest();
    Attributes attr = manifest.getMainAttributes();
    attr.put(Attributes.Name.MANIFEST_VERSION, "1.0");
    attr.put(Attributes.Name.MAIN_CLASS, processor.getClass().getCanonicalName());
    try (JarOutputStream out = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(jar.toFile())), manifest)) {
        List<CompilingClassLoader> classLoaders = processor.getClassLoaders();
        if (classLoaders != null && !classLoaders.isEmpty()) {
            for (CompilingClassLoader classLoader : classLoaders) {
                for (Map.Entry<String, ByteArrayOutputStream> e : classLoader.getClasses().entrySet()) {
                    out.putNextEntry(new ZipEntry(e.getKey().replace(".", "/") + ".class"));
                    out.write(e.getValue().toByteArray());
                    out.closeEntry();
                }
            }
        }
    }
}
Also used : CompilingClassLoader(org.apache.storm.sql.javac.CompilingClassLoader) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) Attributes(java.util.jar.Attributes) JarOutputStream(java.util.jar.JarOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Manifest(java.util.jar.Manifest) BufferedOutputStream(java.io.BufferedOutputStream) Map(java.util.Map) HashMap(java.util.HashMap)

Example 9 with CompilingClassLoader

use of org.apache.storm.sql.javac.CompilingClassLoader in project storm by apache.

the class TridentPlanCreator method createScalarInstance.

public ExecutableExpression createScalarInstance(RexProgram program, String className) throws CompilingClassLoader.CompilerException, ClassNotFoundException, IllegalAccessException, InstantiationException {
    String expr = rexCompiler.compile(program, className);
    CompilingClassLoader classLoader = new CompilingClassLoader(getLastClassLoader(), className, expr, null);
    ExecutableExpression instance = (ExecutableExpression) classLoader.loadClass(className).newInstance();
    addClassLoader(classLoader);
    return new DebuggableExecutableExpression(instance, expr);
}
Also used : CompilingClassLoader(org.apache.storm.sql.javac.CompilingClassLoader) DebuggableExecutableExpression(org.apache.storm.sql.runtime.calcite.DebuggableExecutableExpression) DebuggableExecutableExpression(org.apache.storm.sql.runtime.calcite.DebuggableExecutableExpression) ExecutableExpression(org.apache.storm.sql.runtime.calcite.ExecutableExpression)

Example 10 with CompilingClassLoader

use of org.apache.storm.sql.javac.CompilingClassLoader in project storm by apache.

the class PlanCompiler method compile.

public AbstractValuesProcessor compile(RelNode plan) throws Exception {
    String javaCode = generateJavaSource(plan);
    LOG.debug("Compiling... source code {}", javaCode);
    ClassLoader cl = new CompilingClassLoader(getClass().getClassLoader(), PACKAGE_NAME + ".Processor", javaCode, null);
    return (AbstractValuesProcessor) cl.loadClass(PACKAGE_NAME + ".Processor").newInstance();
}
Also used : CompilingClassLoader(org.apache.storm.sql.javac.CompilingClassLoader) CompilingClassLoader(org.apache.storm.sql.javac.CompilingClassLoader) AbstractValuesProcessor(org.apache.storm.sql.runtime.AbstractValuesProcessor)

Aggregations

CompilingClassLoader (org.apache.storm.sql.javac.CompilingClassLoader)12 DebuggableExecutableExpression (org.apache.storm.sql.runtime.calcite.DebuggableExecutableExpression)4 ExecutableExpression (org.apache.storm.sql.runtime.calcite.ExecutableExpression)4 Config (org.apache.storm.Config)3 BufferedOutputStream (java.io.BufferedOutputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileOutputStream (java.io.FileOutputStream)2 Map (java.util.Map)2 Attributes (java.util.jar.Attributes)2 JarOutputStream (java.util.jar.JarOutputStream)2 Manifest (java.util.jar.Manifest)2 ZipEntry (java.util.zip.ZipEntry)2 DataContext (org.apache.calcite.DataContext)2 RexBuilder (org.apache.calcite.rex.RexBuilder)2 HashMap (java.util.HashMap)1 SqlNode (org.apache.calcite.sql.SqlNode)1 LocalCluster (org.apache.storm.LocalCluster)1 LocalTopology (org.apache.storm.LocalCluster.LocalTopology)1 StormTopology (org.apache.storm.generated.StormTopology)1 AbstractStreamsProcessor (org.apache.storm.sql.AbstractStreamsProcessor)1