I think I saw a message asking the same thing but I'm unable to dig it up
as I can't quite remember the subject. Is there a test class that executes
SQL queries and access the results without using the JDBC API ?

Here is my attempt:
---------------
Planner planner = Frameworks.getPlanner(frameworkConfig); //
frameworkConfig programs is set usign "Programs.standard()"

SqlNode parsed = planner.parse("SELECT 1 + 1 FROM myschema.mytable limit 1"
); // Assume the existense of "myschema.mytable", don't try (VALUES())
SqlNode validated = planner.validate(parsed);
RelNode converted = planner.rel(validated).rel;
RelNode planned = planner.transform(0,
converted.getTraitSet().replace(EnumerableConvention.INSTANCE), converted);

TestDataContext dataContext = new TestDataContext(rootSchema,
(JavaTypeFactory) planner.getTypeFactory()); // A context that provides the
root schema and the java type factory only
try (Interpreter interpreter = new Interpreter(dataContext, planned)) {
    Enumerator<Object[]> results = interpreter.asEnumerable().enumerator();
    while(results.moveNext()) {
        System.out.println(Arrays.toString(results.current()));
    }
}
---------------
This fails and throws the following error
Exception in thread "main" java.lang.AssertionError: interpreter: no
implementation for class
org.apache.calcite.adapter.enumerable.EnumerableInterpreter
at
org.apache.calcite.interpreter.Interpreter$CompilerImpl.visit(Interpreter.java:460)
at org.apache.calcite.interpreter.Nodes$CoreCompiler.visit(Nodes.java:42)
at org.apache.calcite.rel.SingleRel.childrenAccept(SingleRel.java:72)
at
org.apache.calcite.interpreter.Interpreter$CompilerImpl.visit(Interpreter.java:447)
at org.apache.calcite.interpreter.Nodes$CoreCompiler.visit(Nodes.java:42)
at
org.apache.calcite.interpreter.Interpreter$CompilerImpl.visitRoot(Interpreter.java:405)
at org.apache.calcite.interpreter.Interpreter.<init>(Interpreter.java:88)

The output of RelOptUtil.toString(planned) is
EnumerableCalc(expr#0..22=[{inputs}], expr#23=[1], expr#24=[2],
expr#25=[+($t23, $t24)], EXPR$0=[$t25])
  EnumerableLimit(fetch=[1])
    EnumerableInterpreter
      BindableTableScan(table=[[myschema, mytable]])

The reason for this is the converter node "EnumerableInterpreter"
converting from the bindable table scan node to an enumerable convention
node.

Thanks,
Gelbana

Reply via email to