PHOENIX-4139 Incorrect query result for trailing duplicate GROUP BY expression 
(Csaba Skrabak)


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

Branch: refs/heads/4.x-cdh5.11.2
Commit: eb3458912df6fe9c94f96ae4caa1062145f007a4
Parents: 37553f0
Author: James Taylor <jtay...@salesforce.com>
Authored: Sun Mar 11 09:56:20 2018 -0700
Committer: James Taylor <jtay...@salesforce.com>
Committed: Sun Mar 11 10:04:36 2018 -0700

----------------------------------------------------------------------
 .../org/apache/phoenix/end2end/AggregateIT.java | 23 ++++++++++++++++++++
 .../phoenix/schema/RowKeyValueAccessor.java     |  2 +-
 2 files changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/eb345891/phoenix-core/src/it/java/org/apache/phoenix/end2end/AggregateIT.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AggregateIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AggregateIT.java
index a7344cd..fd1d660 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AggregateIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AggregateIT.java
@@ -74,6 +74,29 @@ public class AggregateIT extends ParallelStatsDisabledIT {
     }
 
     @Test
+    public void testDuplicateTrailingAggExpr() throws Exception {
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        String tableName = generateUniqueName();
+        conn.createStatement().execute("create table " + tableName +
+                "   (nam VARCHAR(20), address VARCHAR(20), id BIGINT "
+                + "constraint my_pk primary key (id))");
+        PreparedStatement statement = conn.prepareStatement("UPSERT INTO " + 
tableName + "(nam, address, id) values (?,?,?)");
+        statement.setString(1, "pulkit");
+        statement.setString(2, "badaun");
+        statement.setInt(3, 1);
+        statement.executeUpdate();
+        conn.commit();
+        Statement stmt = conn.createStatement();
+        ResultSet rs = stmt.executeQuery("select distinct 'harshit' as 
\"test_column\", trim(nam), trim(nam) from " + tableName);
+        assertTrue(rs.next());
+        assertEquals("harshit", rs.getString(1));
+        assertEquals("pulkit", rs.getString(2));
+        assertEquals("pulkit", rs.getString(3));
+        conn.close();
+    }
+
+    @Test
     public void testExpressionInGroupBy() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
         Connection conn = DriverManager.getConnection(getUrl(), props);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/eb345891/phoenix-core/src/main/java/org/apache/phoenix/schema/RowKeyValueAccessor.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/schema/RowKeyValueAccessor.java 
b/phoenix-core/src/main/java/org/apache/phoenix/schema/RowKeyValueAccessor.java
index cd82748..1c56d13 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/schema/RowKeyValueAccessor.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/schema/RowKeyValueAccessor.java
@@ -88,7 +88,7 @@ public class RowKeyValueAccessor implements Writable   {
         }
         // Remember this so that we don't bother looking for the null 
separator byte in this case
         this.isFixedLength = datum.getDataType().isFixedWidth();
-        this.hasSeparator = !isFixedLength && (datum != 
data.get(data.size()-1));
+        this.hasSeparator = !isFixedLength && iterator.hasNext();
     }
     
     RowKeyValueAccessor(int[] offsets, boolean isFixedLength, boolean 
hasSeparator) {

Reply via email to