Search in sources :

Example 1 with ArrayBindable

use of org.apache.calcite.runtime.ArrayBindable 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);
    }
}
Also used : Serializable(java.io.Serializable) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) JaninoCompiler(org.apache.calcite.util.javac.JaninoCompiler) ArrayBindable(org.apache.calcite.runtime.ArrayBindable) File(java.io.File) Writer(java.io.Writer)

Example 2 with ArrayBindable

use of org.apache.calcite.runtime.ArrayBindable in project calcite by apache.

the class EnumerableBindable method bind.

public Enumerable<Object[]> bind(DataContext dataContext) {
    final ImmutableMap<String, Object> map = ImmutableMap.of();
    final Bindable bindable = EnumerableInterpretable.toBindable(map, null, (EnumerableRel) getInput(), EnumerableRel.Prefer.ARRAY);
    final ArrayBindable arrayBindable = EnumerableInterpretable.box(bindable);
    return arrayBindable.bind(dataContext);
}
Also used : ArrayBindable(org.apache.calcite.runtime.ArrayBindable) ArrayBindable(org.apache.calcite.runtime.ArrayBindable) Bindable(org.apache.calcite.runtime.Bindable)

Example 3 with ArrayBindable

use of org.apache.calcite.runtime.ArrayBindable in project calcite by apache.

the class EnumerableInterpretable method implement.

public Node implement(final InterpreterImplementor implementor) {
    final Bindable bindable = toBindable(implementor.internalParameters, implementor.spark, (EnumerableRel) getInput(), EnumerableRel.Prefer.ARRAY);
    final ArrayBindable arrayBindable = box(bindable);
    final Enumerable<Object[]> enumerable = arrayBindable.bind(implementor.dataContext);
    return new EnumerableNode(enumerable, implementor.compiler, this);
}
Also used : ArrayBindable(org.apache.calcite.runtime.ArrayBindable) ArrayBindable(org.apache.calcite.runtime.ArrayBindable) Bindable(org.apache.calcite.runtime.Bindable)

Aggregations

ArrayBindable (org.apache.calcite.runtime.ArrayBindable)3 Bindable (org.apache.calcite.runtime.Bindable)2 File (java.io.File)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 Writer (java.io.Writer)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 JaninoCompiler (org.apache.calcite.util.javac.JaninoCompiler)1