If you decide to write a RelOptRule, your rule could perhaps match RelNode(Sort) rather than Sort, and therefore the rule will not fire at the top-level.
However, you could also do the transformation on RelToSqlConverter, which is a more conventional visitor; you can look at the stack to see whether you are at the top. You should add code to the dialect, similar to how SqlNode.emulateNullDirection works, and add dialect tests. Julian > On Apr 14, 2019, at 4:45 AM, Andrew O <[email protected]> wrote: > > I am trying out Calcite against a DBMS that does not support the limit > syntax in nested / sub queries. (The JOOQ blog captures more details / > examples at: > https://www.jooq.org/doc/3.1/manual/sql-building/sql-statements/select-statement/limit-clause/#N467A6 > ) > > I'm interested in how I could have similar behaviour in Calcite. My > starting attempt / thinking is that it needs a JDBC rule that re-writes / > adjusts Sort operations based on the relevant SqlDialect. However I'm not > sure if / how I can match only sorts within nested queries and avoid > changing the root / non-nested limit operations. > > > Is this the correct thinking? Is there any relevant examples to look at for > this? > > Thanks > > Andrew
