use of org.apache.calcite.util.javac.JaninoCompiler in project calcite by apache.
the class SparkHandlerImpl method compile.
public ArrayBindable compile(ClassDeclaration expr, String s) {
final String className = "CalciteProgram" + classId.getAndIncrement();
final File file = new File(SRC_DIR, className + ".java");
try (Writer w = Util.printWriter(file)) {
String source = "public class " + className + "\n" + " implements " + ArrayBindable.class.getName() + ", " + Serializable.class.getName() + " {\n" + s + "\n" + "}\n";
System.out.println("======================");
System.out.println(source);
System.out.println("======================");
w.write(source);
w.close();
JaninoCompiler compiler = new JaninoCompiler();
compiler.getArgs().setDestdir(CLASS_DIR.getAbsolutePath());
compiler.getArgs().setSource(source, file.getAbsolutePath());
compiler.getArgs().setFullClassName(className);
compiler.compile();
@SuppressWarnings("unchecked") final Class<ArrayBindable> clazz = (Class<ArrayBindable>) Class.forName(className);
final Constructor<ArrayBindable> constructor = clazz.getConstructor();
return constructor.newInstance();
} catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
throw new RuntimeException(e);
}
}
Aggregations