By the time the query is translated into relational algebra, SELECT
DISTINCT will have been converted into an Aggregate with no aggregate
functions.

So, for instance,

  select distinct deptno from emp

and

  select deptno from emp group by deptno

will be indistinguishable if you look at the relational algebra.

You should write a rule that matches a Sort on top of an Aggregate
that uses the same keys.

Also, I don't know whether your system supports primary keys. But if,
for example, empno is unique, then you would want to be able to
evaluate

  select empno from emp order by empno

even though there is no explicit SELECT DISTINCT. You can use the
RelMdUniqueKeys metadata to figure out whether the sort key is already
unique.

Julian


On Fri, May 13, 2016 at 8:22 AM, Tzolov, Christian <ctzo...@pivotal.io> wrote:
> Hi there,
>
> I am working on a Calcite adapter for a datastore that supports a limited 
> subset of SQL expressions. My goal is to push down the supported expression.
>
> This datastore supports "ORDER BY” only if the SELECT DISTINCT expression is 
> used.
>
> What would be the best way to check if the select DISTINCT keyword is used 
> from within my SortRule implementation?
>
> Thanks,
> Christian
>

Reply via email to