You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@phoenix.apache.org by "Sergey Soldatov (JIRA)" <ji...@apache.org> on 2016/05/06 09:48:12 UTC

[jira] [Updated] (PHOENIX-2876) Using aggregation function in ORDER BY

     [ https://issues.apache.org/jira/browse/PHOENIX-2876?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Sergey Soldatov updated PHOENIX-2876:
-------------------------------------
    Attachment: PHOENIX-2876-1.patch

It's more like a workaround rather than solution. Any suggestions how to do it better are welcome. 
The problem is that when order by number of column was implemented the orderby compilation was moved after RowProjector compilation, so RowProjector miss all expressions that are in Order By clause. So I added a new method {{precompile}} that compile all order by nodes to collect expressions and this method is called before RowProjector compiled. I bet there are more elegant ways to fix it, but atm I tried to minimize changes in the logic.  

> Using aggregation function in ORDER BY
> --------------------------------------
>
>                 Key: PHOENIX-2876
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-2876
>             Project: Phoenix
>          Issue Type: Bug
>    Affects Versions: 4.7.0
>            Reporter: Sergey Soldatov
>            Assignee: Sergey Soldatov
>         Attachments: PHOENIX-2876-1.patch
>
>
> {noformat}
> create table x (id integer primary key, i1 integer, i2 integer);
> upsert into x values (1, 1, 1);
> upsert into x values (2, 2, 2);
> upsert into x values (3, 2, 3);
> upsert into x values (4, 3, 3);
> upsert into x values (5, 3, 2);
> upsert into x values (6, 3, 1);
> {noformat}
> Test query:
> {noformat}
> select i1 from X group by i1 order by avg(i2) desc;
> {noformat}
> Expected result: 2, 3, 1
> Real result : 1, 3, 2
> In other hands 
> {noformat}
> select i1, avg(i2) from X group by i1 order by avg(i2) desc;
> {noformat}
> works correctly. 
> That happens because in ORDER BY we add nothing to RowProjector if we deal with aggregate functions. So, there is a question. Do we have any restrictions why we can't add the expression from ORDER BY to RowProjector ?  



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)