[
https://issues.apache.org/jira/browse/PHOENIX-2876?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15274574#comment-15274574
]
James Taylor commented on PHOENIX-2876:
---------------------------------------
Not sure what's going on here, but OrderByCompiler.compile() uses an
ExpressionCompiler which should find the reference to i2 and add it to the
context.getScan(). Perhaps the visitor is getting confused because the ORDER BY
expression is a aggregate function and not traversing (that's my best guess).
The ProjectionCompiler projects expressions found in the SELECT clause, so it
shouldn't have an impact.
Add a unit test in WhereCompilerTest or QueryCompileTest as there's no need to
spin up a mini cluster. You can compile the query and then check the familyMap
in the scan hanging off the StatementContext.
> 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
> Fix For: 4.8.0
>
> 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)