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/8c6cc47a Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/8c6cc47a Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/8c6cc47a Branch: refs/heads/4.x-HBase-1.2 Commit: 8c6cc47a6310f068eeaab6f28f3f419f9ac590ea Parents: a59752d 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:01:58 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/8c6cc47a/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/8c6cc47a/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) {