You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@metamodel.apache.org by Ankit Kumar <ak...@gmail.com> on 2015/10/27 18:05:27 UTC

QUESTION | Count (distinct column)

Hi All,

In the Metamodel API is it possible to write a query for the below JDBC
query.

select count(distinct columnA) from tableX ;

I somehow cannot find a way to write such a query using the Query API.

Am I missing something or is this something to be added in the API ?

Regards
Ankit

Re: QUESTION | Count (distinct column)

Posted by Kasper Sørensen <i....@gmail.com>.
Hi Ankit,

Good question.

Today there's only a way to fire an _equivalent_ query using a subquery. Of
this form:

  SELECT COUNT(*) FROM (SELECT DISTINCT columnA FROM tableX)

or alternatively:

  SELECT COUNT(*) FROM (SELECT columnA FROM tableX GROUP BY columnA)

I believe that adding a count distinct function would be possible tho'.
It's just not there yet. The suggestion was registered in JIRA quite some
time ago [1], but recently we made it much easier to plug in new functions,
so now might be the time to consider adding it.

Regards,
Kasper

[1] https://issues.apache.org/jira/browse/METAMODEL-168


2015-10-27 18:05 GMT+01:00 Ankit Kumar <ak...@gmail.com>:

> Hi All,
>
> In the Metamodel API is it possible to write a query for the below JDBC
> query.
>
> select count(distinct columnA) from tableX ;
>
> I somehow cannot find a way to write such a query using the Query API.
>
> Am I missing something or is this something to be added in the API ?
>
> Regards
> Ankit
>