[
https://issues.apache.org/jira/browse/PHOENIX-4540?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16342924#comment-16342924
]
Ankit Singhal commented on PHOENIX-4540:
----------------------------------------
{quote}We don't re-evaluate the expression on the client side. We get the value
of round(k/v,0) from the row key of the rows we get back from the server. The
server returns the aggregated rows with a row key based on the GROUP BY
expressions, so the first part of the returned row key should have the
evaluated value of round(k/v,0).
{quote}
Yes [~jamestaylor], currently this holds true only if we don't have a column
expression in GROUP BY which is a part of arithmetic operation common to
PROJECTION and GROUP BY
For eg:-
This will take evaluated value from group by:-
{code:java}
select k/v x from round_test group by x{code}
but if we add "v" to the GROUP BY.
{code:java}
select k/v x from round_test group by x,v{code}
Here, groupBy compiler will evaluate "x" as
LongDivideExpression(RowKeyExpression, KeyValueExpression) and "v" as
KeyValueExpression but Projection compiler finds "v" in GROUP BY and evaluate
"v" as RowKeyExpression so now the projection expression for "x" would be
LongDivideExpression(RowKeyExpression, RowKeyExpression) which will not match
the expression in GROUP BY and therefore, it will try to re-evaluate the same
at the client , which will fail eventually as "K" is not a part of RowKey
returned by GROUP BY.
{quote}Does this slightly simpler test fail too? It's a bit strange to group by
both round(k/v,0) and v.
{quote}
Actually, this will fail for any expression which is part of Arithmetic
operations is also a part of GROUP BY.
select col1+col2+col3-col4/col5 as x, col6 group by x,col2,col6
> Client side evaluation of group by Expression in projection gives erroneous
> result
> ----------------------------------------------------------------------------------
>
> Key: PHOENIX-4540
> URL: https://issues.apache.org/jira/browse/PHOENIX-4540
> Project: Phoenix
> Issue Type: Bug
> Reporter: Ankit Singhal
> Priority: Major
> Attachments: PHOENIX-4540_unittest.patch
>
>
> If the columns involved in projected expression are not present in "group by"
> clause, the client evaluation of the same expression will give an erroneous
> result because of the absence of involved column value.
> Following queries will produce wrong result
> >select round(k/v,0) x from round_test group by x,v
> >select k/v x from round_test group by x,v
> but query runs fine if we add all columns so that client expression can be
> evaluated
> >select round(k/v,0) x from round_test group by x,k,v //will produce right
> >result
> >select k/v x from round_test group by x,k,v;
> Why we need to re-evaluate the expression here, can't we use the same result
> evaluated at server side during the "group by"
> thoughts [~jamestaylor]?
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)