[ 
https://issues.apache.org/jira/browse/PHOENIX-18?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13891670#comment-13891670
 ] 

Anoop Sam John commented on PHOENIX-18:
---------------------------------------

Sorry James. I should have said that (The reason for the bug)

Yes even if the alias used correctly things wont work out.  In fact when the 
query contains an Order by (On any of the selected column) all the distinct 
based aggregation was not getting back the correct value.  :(

Reason
-----------
When we have order by we will be having a OrderedAggregatingResultIterator 
around the AggregatingResultIterator and we will be fetching all the result 
rows back to client (So that we can do the sort at client). For all client side 
aggregators of type DistinctValueWithCountClientAggregator, we will be sending 
a Map info from server. Well this comes correctly into aggregate() and we do 
calculations and all the look ahead results in OrderedResultIterator are 
correct. Now again when each of the result is retrieved by client code using 
next() calls, we will doing aggregate once again. At this time there is no Map 
bytes in the ImmutableBytesWritable ptr. This will contain the actual result 
then.  With the code change I am getting this result.  Why this is not an issue 
with other aggregators like sum is in that case both the times the aggregate 
gets the same type of data int or float.

Now you can see the tests added. All the distinct based aggregations are 
corrected. One can do ordering on aggregate column or on aggregated value. :) 



>  (count(distinct col)) DESC sort process not working
> ----------------------------------------------------
>
>                 Key: PHOENIX-18
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-18
>             Project: Phoenix
>          Issue Type: Bug
>         Environment: Cloudera 4.5
>            Reporter: saravanan
>            Assignee: Anoop Sam John
>         Attachments: PHOENIX-18.patch
>
>   Original Estimate: 12h
>  Remaining Estimate: 12h
>
> I run the below query and not getting the expected result...
> SELECT "tbp__VPN" as "Part Number",Count(distinct "tbp__EGN") as "egn Number" 
> FROM "AL_V_PNO_DEMO" WHERE ("tbp__VPN" is not null) GROUP BY "tbp__VPN" ORDER 
> BY  'egn Number' DESC /* +SKIP_SCAN */;
>       the above query executes fine but the sorting is not done for ORDER BY 
> column..Is its problem with the Query or Its some Bug in Phoenix.



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Reply via email to