[
https://issues.apache.org/jira/browse/PHOENIX-988?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14004477#comment-14004477
]
James Taylor commented on PHOENIX-988:
--------------------------------------
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:
{code}
Index:
phoenix-core/src/main/java/org/apache/phoenix/expression/CaseExpression.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
---
phoenix-core/src/main/java/org/apache/phoenix/expression/CaseExpression.java
(revision 332746)
+++
phoenix-core/src/main/java/org/apache/phoenix/expression/CaseExpression.java
(revision )
@@ -46,7 +46,7 @@
private short evalIndex = FULLY_EVALUATE;
private boolean foundIndex;
private PDataType returnType;
-
+
public CaseExpression() {
}
@@ -186,7 +186,7 @@
// to evaluate all cases, but didn't find any matches.
return size;
}
-
+
/**
* Only expression that currently uses the isPartial flag. The IS NULL
* expression will use it too. TODO: We could alternatively have a non
interface
@@ -196,13 +196,13 @@
@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 true;
+ if (!children.get(index).evaluate(tuple, ptr) || ptr.getLength() == 0)
{
+ return false;
}
- 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)