Repository: phoenix
Updated Branches:
  refs/heads/master 867af78dd -> 4774c6332


PHOENIX-1203 Uable to work for count (distinct col) queries via phoenix table 
with secondary indexes.


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

Branch: refs/heads/master
Commit: 4774c63320517fed15c4f4e3ef0a03fdbc597b06
Parents: 867af78
Author: anoopsjohn <anoopsamj...@gmail.com>
Authored: Mon Sep 1 09:13:38 2014 +0530
Committer: anoopsjohn <anoopsamj...@gmail.com>
Committed: Mon Sep 1 09:13:38 2014 +0530

----------------------------------------------------------------------
 .../apache/phoenix/end2end/DistinctCountIT.java | 45 ++++++++++++++++++++
 .../apache/phoenix/parse/ParseNodeFactory.java  |  2 +-
 2 files changed, 46 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/4774c633/phoenix-core/src/it/java/org/apache/phoenix/end2end/DistinctCountIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DistinctCountIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DistinctCountIT.java
index 62fa0f5..4b76d29 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DistinctCountIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DistinctCountIT.java
@@ -45,6 +45,7 @@ import java.sql.ResultSet;
 import java.sql.Types;
 import java.util.Properties;
 
+import org.apache.phoenix.schema.TableAlreadyExistsException;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.junit.Test;
@@ -458,4 +459,48 @@ public class DistinctCountIT extends 
BaseClientManagedTimeIT {
             conn.close();
         }
     }
+
+    @Test
+    public void testDistinctCountOnIndexTab() throws Exception {
+        String ddl = "create table personal_details (id integer not null, 
first_name char(15),\n"
+                + "    last_name char(15), CONSTRAINT pk PRIMARY KEY (id))";
+        Properties props = new Properties();
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        try {
+            PreparedStatement stmt = conn.prepareStatement(ddl);
+            stmt.execute(ddl);
+            conn.createStatement().execute("CREATE INDEX personal_details_idx 
ON personal_details(first_name)");
+        } catch (TableAlreadyExistsException e) {
+
+        } finally {
+            conn.close();
+        }
+
+        conn = DriverManager.getConnection(getUrl(), props);
+        try {
+            PreparedStatement stmt = conn.prepareStatement("upsert into 
personal_details(id, first_name, "
+                    + "last_name) VALUES (?, ?, ?)");
+            stmt.setInt(1, 1);
+            stmt.setString(2, "NAME1");
+            stmt.setString(3, "LN");
+            stmt.execute();
+            stmt.setInt(1, 2);
+            stmt.setString(2, "NAME1");
+            stmt.setString(3, "LN2");
+            stmt.execute();
+            stmt.setInt(1, 3);
+            stmt.setString(2, "NAME2");
+            stmt.setString(3, "LN3");
+            stmt.execute();
+            conn.commit();
+
+            String query = "SELECT COUNT (DISTINCT first_name) FROM 
personal_details";
+            PreparedStatement statement = conn.prepareStatement(query);
+            ResultSet rs = statement.executeQuery();
+            assertTrue(rs.next());
+            assertEquals(2, rs.getInt(1));
+        } finally {
+            conn.close();
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4774c633/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java 
b/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
index 5125340..6872f8a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/ParseNodeFactory.java
@@ -345,7 +345,7 @@ public class ParseNodeFactory {
         if 
(CountAggregateFunction.NAME.equals(SchemaUtil.normalizeIdentifier(name))) {
             BuiltInFunctionInfo info = getInfo(
                     
SchemaUtil.normalizeIdentifier(DistinctCountAggregateFunction.NAME), args);
-            return new DistinctCountParseNode(name, args, info);
+            return new 
DistinctCountParseNode(DistinctCountAggregateFunction.NAME, args, info);
         } else {
             throw new UnsupportedOperationException("DISTINCT not supported 
with " + name);
         }

Reply via email to