[
https://issues.apache.org/jira/browse/PHOENIX-4540?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16533082#comment-16533082
]
James Taylor commented on PHOENIX-4540:
---------------------------------------
A little bit more concretely:
* Detect in GroupByCompiler when there's a GROUP BY expression that is a
subset (A) of another GROUP BY expression (B).
* Store a slightly modified version of A in a new List<Expression> member
variable in GroupBy that will enable them to be found in the
{{groupBy.getExpressions().indexOf(expression)}} while the SELECT expressions
are compiled
** The superset expression (B) will be modified by calling
ExpressionCompiler.wrapGroupByExpression() on each expression.
** In your example of {{k/v}} and {{v}}, you'd end up with
DivideExpression(KeyValueColumnExpression, RowKeyColumnExpression(v))
* In ExpressionCompiler, modify wrapGroupByExpression to use a new method to
get the expressions from the GroupBy (instead of using
groupBy.getExpressions()). The returned list should include all the
groupBy.getExpressions() plus the slightly modified ones. This should cause the
modified expression you created to be found.
* Similarly, instead of calling groupBy.getKeyExpressions() in
wrapGroupByExpression, you'd call a new method that would include all the
groupBy.getExpressions() plus the key expressions for the slightly modified
ones (these would be the same key expressions as the originally unmodified key
expression for B. The getExpressions() is parallel with the getKeyExpressions()
list.
I think this will fix the issue.
> 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.patch, 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)