Search in sources :

Example 1 with CompilingClassLoader

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

the class QueryPlanner method compile.

public AbstractTridentProcessor compile(Map<String, ISqlTridentDataSource> sources, String query) throws Exception {
    TridentRel relNode = getPlan(query);
    TridentPlanCreator tridentPlanCreator = new TridentPlanCreator(sources, new RexBuilder(typeFactory));
    relNode.tridentPlan(tridentPlanCreator);
    final TridentTopology topology = tridentPlanCreator.getTopology();
    final IAggregatableStream lastStream = tridentPlanCreator.pop();
    final DataContext dc = tridentPlanCreator.getDataContext();
    final List<CompilingClassLoader> cls = tridentPlanCreator.getClassLoaders();
    return new AbstractTridentProcessor() {

        @Override
        public TridentTopology build() {
            return topology;
        }

        @Override
        public Stream outputStream() {
            return lastStream.toStream();
        }

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

        @Override
        public List<CompilingClassLoader> getClassLoaders() {
            return cls;
        }
    };
}
Also used : AbstractTridentProcessor(org.apache.storm.sql.AbstractTridentProcessor) IAggregatableStream(org.apache.storm.trident.fluent.IAggregatableStream) DataContext(org.apache.calcite.DataContext) CompilingClassLoader(org.apache.storm.sql.javac.CompilingClassLoader) TridentTopology(org.apache.storm.trident.TridentTopology) RexBuilder(org.apache.calcite.rex.RexBuilder) TridentRel(org.apache.storm.sql.planner.trident.rel.TridentRel)

Example 2 with CompilingClassLoader

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

the class TridentPlanCreator method createScalarInstance.

public ExecutableExpression createScalarInstance(List<RexNode> nodes, RelDataType inputRowType, String className) throws CompilingClassLoader.CompilerException, ClassNotFoundException, IllegalAccessException, InstantiationException {
    String expr = rexCompiler.compile(nodes, inputRowType, 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 3 with CompilingClassLoader

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

the class TestPlanCompiler method runTridentTopology.

private void runTridentTopology(final int expectedValueSize, AbstractTridentProcessor proc, TridentTopology topo) throws Exception {
    final Config conf = new Config();
    conf.setMaxSpoutPending(20);
    if (proc.getClassLoaders() != null && proc.getClassLoaders().size() > 0) {
        CompilingClassLoader lastClassloader = proc.getClassLoaders().get(proc.getClassLoaders().size() - 1);
        Utils.setClassLoaderForJavaDeSerialize(lastClassloader);
    }
    try (LocalTopology stormTopo = cluster.submitTopology("storm-sql", conf, topo.build())) {
        waitForCompletion(1000 * 1000, new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                return getCollectedValues().size() < expectedValueSize;
            }
        });
    } finally {
        while (cluster.getClusterInfo().get_topologies_size() > 0) {
            Thread.sleep(10);
        }
        Utils.resetClassLoaderForJavaDeSerialize();
    }
}
Also used : CompilingClassLoader(org.apache.storm.sql.javac.CompilingClassLoader) Config(org.apache.storm.Config) LocalTopology(org.apache.storm.LocalCluster.LocalTopology)

Example 4 with CompilingClassLoader

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

the class SqlTestUtil method runStormTopology.

public static void runStormTopology(LocalCluster cluster, final List<?> watchedList, final int expectedValueSize, AbstractStreamsProcessor proc, StormTopology topo) throws Exception {
    final Config conf = new Config();
    conf.setMaxSpoutPending(20);
    conf.setDebug(true);
    if (proc.getClassLoaders() != null && proc.getClassLoaders().size() > 0) {
        CompilingClassLoader lastClassloader = proc.getClassLoaders().get(proc.getClassLoaders().size() - 1);
        Utils.setClassLoaderForJavaDeSerialize(lastClassloader);
    }
    try (LocalCluster.LocalTopology stormTopo = cluster.submitTopology("storm-sql", conf, topo)) {
        waitForCompletion(1000 * 1000, () -> watchedList.size() < expectedValueSize);
    } finally {
        while (cluster.getTopologySummaries().size() > 0) {
            Thread.sleep(10);
        }
        Utils.resetClassLoaderForJavaDeSerialize();
    }
}
Also used : LocalCluster(org.apache.storm.LocalCluster) CompilingClassLoader(org.apache.storm.sql.javac.CompilingClassLoader) Config(org.apache.storm.Config)

Example 5 with CompilingClassLoader

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

the class StreamsPlanCreator method createScalarInstance.

public ExecutableExpression createScalarInstance(List<RexNode> nodes, RelDataType inputRowType, String className) throws CompilingClassLoader.CompilerException, ClassNotFoundException, IllegalAccessException, InstantiationException {
    String expr = rexCompiler.compile(nodes, inputRowType, 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