Hi Gelbana, I guess you can derive the correct type by looking in the RelDataType of the plan. The method JavaTypeFactory#getJavaClass might be of some help there.
Otherwise you can use an Iterator<Object> as it is for instance in AvaticaResultSet [1]. Best, Stamatis [1] https://github.com/apache/calcite-avatica/blob/8138d42841a599397fa6bedcb53ae694d388f100/core/src/main/java/org/apache/calcite/avatica/AvaticaResultSet.java#L181 On Mon, Jul 29, 2019 at 3:28 PM Muhammad Gelbana <[email protected]> wrote: > Thanks a lot Stamatis, very helpful and responsive as always :) > > Here is what worked perfectly for me so far after building over what you > provided. > > HashMap<String, Object> parameters = new HashMap<>(); > dataContext.setMap(parameters); // A custom context object holding my root > schema and type factory. The setMap method is custom too to provide my own > parameters map > Iterator<Object[]> resultsIterator = > EnumerableInterpretable.toBindable(parameters, null, (EnumerableRel) > planned, EnumerableRel.Prefer.ARRAY).bind(dataContext).iterator(); > // "planned" is the optimized/physical plan. > > Now the "resultsIterator" iterator has all my result set. The tricky part > was that for single column resultsets, the output from the iterator is a > single object, not an Object[]. > > Thanks, > Gelbana > > > On Wed, Jul 17, 2019 at 11:31 PM Stamatis Zampetakis <[email protected]> > wrote: > > > Hi Gelbana, > > > > In [1, 2] you can find rather full end-to-end example with the main > Calcite > > primitives in use. Hope it helps! > > > > Best, > > Stamatis > > > > [1] > > > > > https://github.com/zabetak/calcite/blob/livecodingdemo/core/src/test/java/org/apache/calcite/examples/foodmart/java/EndToEndExampleBindable.java > > [2] > > > > > https://github.com/michaelmior/calcite-notebooks/blob/master/query-optimization.ipynb > > > > On Wed, Jul 17, 2019 at 7:18 PM Muhammad Gelbana <[email protected]> > > wrote: > > > > > 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 > > > > > >
