Thank you very much Stamatis !

On Mon, Nov 29, 2021, 9:37 AM Stamatis Zampetakis <[email protected]> wrote:

> Hi Florent,
>
> First when you post an error/exception it is helpful to have the full stack
> trace to understand better the general context.
>
> Second when you suspect the problem is related to the plan it is also
> a good idea to share the plan in question;
> use
> to
> org.apache.calcite.plan.RelOptUtil#toString(org.apache.calcite.rel.RelNode)
> or another similar API to print the plan.
>
> As you said the reason that you are getting the error is most likely the
> input plan; the relNode that you are passing in the converter.
> I guess the plan contains a RelNode which cannot be handled by the
> `RelToSqlConverter`.
> Usually when this class is used by Calcite all the operators are of the
> form Jdbc* (e.g., JdbcJoin, JdbcFilter, JdbcProject, etc.).
>
> To understand how Calcite transforms operators in SQL, run some test cases
> from JdbcAdapterTest in debug mode and put breakpoints in
> JdbcToEnumerableConverter [1].
>
> Based on this you may need to replace converter.visitRoot with
> converter.visitInput and possibly modify the traitset to have only the
> JdbcConvention.
>
> RelTraitSet desiredTraits = cluster.traitSet().replace(convention);
>
> You can probably use the `RelToSqlConverter` with just Logical or
> Enumerable operators but you may find out that some operators are not
> supported either because it doesn't make sense or because nobody
> implemented support for those till now.
>
> Best,
> Stamatis
>
> [1]
>
> https://github.com/apache/calcite/blob/7c423ef23878271b1c50c03629ebfff674985681/core/src/main/java/org/apache/calcite/adapter/jdbc/JdbcToEnumerableConverter.java#L346
>
>
> On Fri, Nov 26, 2021 at 3:51 PM Florent Martineau <[email protected]
> >
> wrote:
>
> > Hi everyone,
> >
> > I'm having troubles transforming a RelNode to SQL. When running this
> code:
> >
> > RelToSqlConverter converter = new
> > RelToSqlConverter(SqlDialect.DatabaseProduct.CALCITE.getDialect());
> > SqlImplementor.Result result = converter.visitRoot(relNode);
> >
> > I'm getting the following error on visitRoot:
> > Need to implement
> org.apache.calcite.adapter.jdbc.JdbcToEnumerableConverter
> >
> > As the RelToSqlConverter only takes a dialect as an argument, and
> visitRoot
> > a RelNode, I suspect the error comes from the planning.
> >
> > To build my RelNode, I'm running the optimizer. It works without error
> and
> > seems to optimize the statement, but this RelNode seems not suitable for
> > the RelToSqlConverter later on.
> >
> > Here is how I run the optimizer:
> >
> > RelOptCluster cluster = rel.getCluster();
> > RelOptPlanner planner = cluster.getPlanner();
> > // JdbcConvention convention = new JdbcConvention(SqlDialect
> > .DatabaseProduct.CALCITE.getDialect(), new
> > DefaultExpression(RelNode.class), "my_schema");
> > RelTraitSet desiredTraits =
> > cluster.traitSet().plus(EnumerableConvention.INSTANCE);
> > //.plus(convention);
> > RelNode newRoot = planner.changeTraits(rel, desiredTraits);
> > planner.setRoot(newRoot);
> > RelNode optimizedNode = planner.findBestExp();
> >
> > As you can see commented out, I've tried adding the JdbcConvention but it
> > doesn't work, and I don't get how to include the
> JdbcToEnumerableConverter.
> >
> > If you have any hints as to where the error could come from, this would
> be
> > truly awesome!!
> >
> > Have a great day,
> >
> > Florent
> >
>

Reply via email to