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;
}
};
}
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();
}
}
}
}
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();
}
}
}
}
}
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);
}
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();
}
Aggregations