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

James Taylor edited comment on PHOENIX-988 at 5/21/14 8:30 AM:
---------------------------------------------------------------

Thanks for the patch, [~jaywong]. This is definitely a bug. In general, if a 
child expression evaluates to a zero length, that means it is null and should 
not be included in the count. Please try the following change instead, as it's 
a bit simpler and a more general fix for this issue (in 
phoenix-core/src/main/java/org/apache/phoenix/expression/CaseExpression.java):
{code}
     @Override
     public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
         int index = evaluateIndexOf(tuple, ptr);
        if (index < 0) {
             return false;
        } else if (index == children.size()) {
             ptr.set(PDataType.NULL_BYTES);
             return true;
         }
        if (!children.get(index).evaluate(tuple, ptr)) {
             return false;
        }
        return true;
     }
{code}

Please let us know if this solves the problem. It'd be good to add a unit test 
that repros this issue as well.


was (Author: jamestaylor):
Thanks for the patch, [~jaywong]. This is definitely a bug. In general, if a 
child expression evaluates to a zero length, that means it is null and should 
not be included in the count. Please try the following change instead, as it's 
a bit simpler and a more general fix for this issue (in 
phoenix-core/src/main/java/org/apache/phoenix/expression/CaseExpression.java):
     @Override
     public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
         int index = evaluateIndexOf(tuple, ptr);
        if (index < 0) {
             return false;
        } else if (index == children.size()) {
             ptr.set(PDataType.NULL_BYTES);
             return true;
         }
        if (!children.get(index).evaluate(tuple, ptr)) {
             return false;
        }
        return true;
     }
{code}

Please let us know if this solves the problem. It'd be good to add a unit test 
that repros this issue as well.

> The result is not expected when select case when case
> -----------------------------------------------------
>
>                 Key: PHOENIX-988
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-988
>             Project: Phoenix
>          Issue Type: Bug
>    Affects Versions: 3.0.0
>            Reporter: jay wong
>             Fix For: 3.1
>
>         Attachments: PHOENIX-988.patch
>
>
> A table : 
> select count( int_column_a ) count from table1 where int_column_a<10;
> |   COUNT    |
> | 0          |
> then select with sql :
> select count( distinct case when int_column_a<10 then 2 else null end ) count 
> from table1;
> the expected reuslt is 0. but 1 we got.
> As the CaseExcression#evaluate doesn't handle the case.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to