phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ramkris...@apache.org
Subject phoenix git commit: PHOENIX-2063 Row value constructor doesn't work when used in COUNT DISTINCT (Dumindu Buddhika)
Date Thu, 09 Jul 2015 04:50:21 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.0 37099816e -> fb517d375


PHOENIX-2063 Row value constructor doesn't work when used in COUNT
DISTINCT (Dumindu Buddhika)


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

Branch: refs/heads/4.x-HBase-1.0
Commit: fb517d3752c219f91444f25046995f722dcfe30b
Parents: 3709981
Author: ramkrishna <ramkrishna.s.vasudevan@gmail.com>
Authored: Thu Jul 9 10:18:10 2015 +0530
Committer: ramkrishna <ramkrishna.s.vasudevan@gmail.com>
Committed: Thu Jul 9 10:20:00 2015 +0530

----------------------------------------------------------------------
 .../phoenix/end2end/RowValueConstructorIT.java  | 78 ++++++++++++++++++++
 .../aggregator/ServerAggregators.java           |  1 +
 2 files changed, 79 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/fb517d37/phoenix-core/src/it/java/org/apache/phoenix/end2end/RowValueConstructorIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RowValueConstructorIT.java
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RowValueConstructorIT.java
index e227eb0..0cf5455 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/RowValueConstructorIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/RowValueConstructorIT.java
@@ -1423,4 +1423,82 @@ public class RowValueConstructorIT extends BaseClientManagedTimeIT
{
         assertFalse(rs.next());
         conn.close();
     }
+
+    @Test
+    public void testCountDistinct1() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        String ddl = "CREATE TABLE regions1 (region_name VARCHAR PRIMARY KEY, a INTEGER,
b INTEGER)";
+        conn.createStatement().execute(ddl);
+        conn.commit();
+        PreparedStatement stmt = conn.prepareStatement("UPSERT INTO regions1(region_name,
a, b) VALUES('a', 6,3)");
+        stmt.execute();
+        stmt = conn.prepareStatement("UPSERT INTO regions1(region_name, a, b) VALUES('b',
2,4)");
+        stmt.execute();
+        stmt = conn.prepareStatement("UPSERT INTO regions1(region_name, a, b) VALUES('c',
6,3)");
+        stmt.execute();
+        conn.commit();
+        ResultSet rs;
+        rs = conn.createStatement().executeQuery("SELECT COUNT(DISTINCT (a,b)) from regions1");
+        assertTrue(rs.next());
+        assertEquals(2, rs.getInt(1));
+    }
+
+    @Test
+    public void testCountDistinct2() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        String ddl = "CREATE TABLE regions2 (region_name VARCHAR PRIMARY KEY, a VARCHAR,
b VARCHAR)";
+        conn.createStatement().execute(ddl);
+        conn.commit();
+        PreparedStatement stmt = conn.prepareStatement("UPSERT INTO regions2(region_name,
a, b) VALUES('a', 'fooo','abc')");
+        stmt.execute();
+        stmt = conn.prepareStatement("UPSERT INTO regions2(region_name, a, b) VALUES('b',
'off','bac')");
+        stmt.execute();
+        stmt = conn.prepareStatement("UPSERT INTO regions2(region_name, a, b) VALUES('c',
'fooo', 'abc')");
+        stmt.execute();
+        conn.commit();
+        ResultSet rs;
+        rs = conn.createStatement().executeQuery("SELECT COUNT(DISTINCT (a,b)) from regions2");
+        assertTrue(rs.next());
+        assertEquals(2, rs.getInt(1));
+    }
+
+    @Test
+    public void testCountDistinct3() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        String ddl = "CREATE TABLE regions3 (region_name VARCHAR PRIMARY KEY, a Boolean,
b Boolean)";
+        conn.createStatement().execute(ddl);
+        conn.commit();
+        PreparedStatement stmt = conn.prepareStatement("UPSERT INTO regions3(region_name,
a, b) VALUES('a', true, true)");
+        stmt.execute();
+        stmt = conn.prepareStatement("UPSERT INTO regions3(region_name, a, b) VALUES('b',
true, False)");
+        stmt.execute();
+        stmt = conn.prepareStatement("UPSERT INTO regions3(region_name, a, b) VALUES('c',
true, true)");
+        stmt.execute();
+        stmt = conn.prepareStatement("UPSERT INTO regions3(region_name, a, b) VALUES('d',
true, false)");
+        stmt.execute();
+        conn.commit();
+        ResultSet rs;
+        rs = conn.createStatement().executeQuery("SELECT COUNT(DISTINCT (a,b)) from regions3");
+        assertTrue(rs.next());
+        assertEquals(2, rs.getInt(1));
+    }
+
+    @Test
+    public void testCountDistinct4() throws Exception {
+        Connection conn = DriverManager.getConnection(getUrl());
+        String ddl = "CREATE TABLE regions4 (region_name VARCHAR PRIMARY KEY, a VARCHAR,
b VARCHAR)";
+        conn.createStatement().execute(ddl);
+        conn.commit();
+        PreparedStatement stmt = conn.prepareStatement("UPSERT INTO regions4(region_name,
a, b) VALUES('a', 'fooo','abc')");
+        stmt.execute();
+        stmt = conn.prepareStatement("UPSERT INTO regions4(region_name, a, b) VALUES('b',
'off','bac')");
+        stmt.execute();
+        stmt = conn.prepareStatement("UPSERT INTO regions4(region_name, a, b) VALUES('c',
'foo', 'abc')");
+        stmt.execute();
+        conn.commit();
+        ResultSet rs;
+        rs = conn.createStatement().executeQuery("SELECT COUNT(DISTINCT (a,b)) from regions4");
+        assertTrue(rs.next());
+        assertEquals(3, rs.getInt(1));
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/fb517d37/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 8792c91..01ca733 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
@@ -59,6 +59,7 @@ public class ServerAggregators extends Aggregators {
             if (expressions[i].evaluate(result, ptr) && ptr.getLength() != 0) {
                 aggregators[i].aggregate(result, ptr);
             }
+            expressions[i].reset();
         }
     }
     


Mime
View raw message