Yes, this is possible. In fact Phoenix does exactly this. Take a look at https://issues.apache.org/jira/browse/CALCITE-818 and https://issues.apache.org/jira/browse/CALCITE-71, which were fixed along the way.
> On Oct 29, 2015, at 1:16 AM, Alexander Reshetov > <[email protected]> wrote: > > Hello, > > I have kinda theoretical question. But it should help to understand > overall Calcite's possibility. > > Suppose there is some abstract format/table, which supports only > sorting by one column. > > Let's say there is next query passed to calcite: > > select * from table order by id > > Is it possible to rewrite query tree so it will change this request into this? > > select * from table > > In this way after logical query rewrite Calcite should not be > concerned about sorting at all.
