Repository: phoenix
Updated Branches:
  refs/heads/4.0 d27353ad2 -> 2bcc1d148


PHOENIX-965 Cannot aggregate on index with NULL values


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/2bcc1d14
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/2bcc1d14
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/2bcc1d14

Branch: refs/heads/4.0
Commit: 2bcc1d14889685ecc6187fb33684aece74de51c3
Parents: d27353a
Author: James Taylor <jtay...@salesforce.com>
Authored: Wed Aug 13 21:17:46 2014 -0700
Committer: James Taylor <jtay...@salesforce.com>
Committed: Thu Aug 14 11:28:39 2014 -0700

----------------------------------------------------------------------
 .../org/apache/phoenix/end2end/QueryIT.java     | 37 ++++++++++++++++++++
 .../aggregator/ServerAggregators.java           |  3 +-
 2 files changed, 38 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/2bcc1d14/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java
index 35140f4..c9ec25e 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/QueryIT.java
@@ -792,4 +792,41 @@ public class QueryIT extends BaseQueryIT {
             conn.close();
         }
     }
+
+    @Test
+    public void testSumOverNullIntegerColumn() throws Exception {
+        String query = "SELECT sum(a_integer) FROM aTable a";
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts 
+ 2));
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        conn.setAutoCommit(true);
+        conn.createStatement().execute("UPSERT INTO 
atable(organization_id,entity_id,a_integer) VALUES('" + getOrganizationId() + 
"','" + ROW3 + "',NULL)");
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts 
+ 5));
+        conn = DriverManager.getConnection(getUrl(), props);
+        try {
+            PreparedStatement statement = conn.prepareStatement(query);
+            ResultSet rs = statement.executeQuery();
+            assertTrue (rs.next());
+            assertEquals(42, rs.getInt(1));
+            assertFalse(rs.next());
+        } finally {
+            conn.close();
+        }
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts 
+ 7));
+        conn = DriverManager.getConnection(getUrl(), props);
+        conn.setAutoCommit(true);
+        conn.createStatement().execute("UPSERT INTO 
atable(organization_id,entity_id,a_integer) SELECT organization_id, entity_id, 
null FROM atable");
+        props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts 
+ 9));
+        conn = DriverManager.getConnection(getUrl(), props);
+        try {
+            PreparedStatement statement = conn.prepareStatement(query);
+            ResultSet rs = statement.executeQuery();
+            assertTrue (rs.next());
+            assertEquals(0, rs.getInt(1));
+            assertTrue(rs.wasNull());
+            assertFalse(rs.next());
+        } finally {
+            conn.close();
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/2bcc1d14/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/ServerAggregators.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/ServerAggregators.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/ServerAggregators.java
index 1ddda5d..8792c91 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/ServerAggregators.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/aggregator/ServerAggregators.java
@@ -27,7 +27,6 @@ import java.util.List;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.io.WritableUtils;
-
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.ExpressionType;
 import org.apache.phoenix.expression.function.SingleAggregateFunction;
@@ -57,7 +56,7 @@ public class ServerAggregators extends Aggregators {
     @Override
     public void aggregate(Aggregator[] aggregators, Tuple result) {
         for (int i = 0; i < expressions.length; i++) {
-            if (expressions[i].evaluate(result, ptr)) {
+            if (expressions[i].evaluate(result, ptr) && ptr.getLength() != 0) {
                 aggregators[i].aggregate(result, ptr);
             }
         }

Reply via email to