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/f0d3809d
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/f0d3809d
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/f0d3809d

Branch: refs/heads/4.x-HBase-0.98
Commit: f0d3809d281956cdb0ea2194111cf1a739f8251a
Parents: 71eb204
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:28:35 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/f0d3809d/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 3d0e590..c5c1145 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/f0d3809d/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