Search in sources :

Example 11 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, AbstractStreamsProcessor 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)

Example 12 with CompilingClassLoader

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

the class StreamsPlanCreator 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)

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