Repository: phoenix Updated Branches: refs/heads/4.x-HBase-1.1 7a4a974d3 -> d200b5165
PHOENIX-4283 fix a coearceByte issue which causes nested group by big int incorrect Signed-off-by: aertoria <casti...@gmail.com> Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/7d2c1edd Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/7d2c1edd Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/7d2c1edd Branch: refs/heads/4.x-HBase-1.1 Commit: 7d2c1edd66cf7fb2df17a13884bb6b5e4acdbe48 Parents: 7a4a974 Author: aertoria <casti...@gmail.com> Authored: Sun Oct 15 18:36:44 2017 -0700 Committer: James Taylor <jtay...@salesforce.com> Committed: Wed Nov 15 10:38:41 2017 -0800 ---------------------------------------------------------------------- .../org/apache/phoenix/end2end/AggregateIT.java | 21 +++++++++++++++++++- .../org/apache/phoenix/schema/types/PLong.java | 3 ++- 2 files changed, 22 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/7d2c1edd/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 67a468a..3d0e590 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 @@ -936,7 +936,26 @@ public class AggregateIT extends ParallelStatsDisabledIT { public void testCountNullInNonEncodedNonEmptyKeyValueCF() throws Exception { testCountNullInNonEmptyKeyValueCF(0); } - + + @Test + public void testNestedGroupedAggregationWithBigInt() throws Exception { + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + String tableName = generateUniqueName(); + try(Connection conn = DriverManager.getConnection(getUrl(), props);) { + String createQuery="CREATE TABLE "+tableName+" (a BIGINT NOT NULL,c BIGINT NOT NULL CONSTRAINT PK PRIMARY KEY (a, c))"; + String updateQuery="UPSERT INTO "+tableName+"(a,c) VALUES(4444444444444444444, 5555555555555555555)"; + String query="SELECT a FROM (SELECT a, c FROM "+tableName+" GROUP BY a, c) GROUP BY a, c"; + conn.prepareStatement(createQuery).execute(); + conn.prepareStatement(updateQuery).execute(); + conn.commit(); + PreparedStatement statement = conn.prepareStatement(query); + ResultSet rs = statement.executeQuery(); + assertTrue(rs.next()); + assertEquals(4444444444444444444L,rs.getLong(1)); + assertFalse(rs.next()); + } + } + private void testCountNullInNonEmptyKeyValueCF(int columnEncodedBytes) throws Exception { try (Connection conn = DriverManager.getConnection(getUrl())) { //Type is INT http://git-wip-us.apache.org/repos/asf/phoenix/blob/7d2c1edd/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PLong.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PLong.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PLong.java index 0402c6e..acd16c5 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PLong.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/types/PLong.java @@ -133,8 +133,9 @@ public class PLong extends PWholeNumber<Long> { public void coerceBytes(ImmutableBytesWritable ptr, Object object, PDataType actualType, Integer maxLength, Integer scale, SortOrder actualModifier, Integer desiredMaxLength, Integer desiredScale, SortOrder expectedModifier) { + // Decrease size of TIMESTAMP to size of LONG and continue coerce - if (ptr.getLength() > getByteSize()) { + if (ptr.getLength() > getByteSize() && actualType.isCoercibleTo(PTimestamp.INSTANCE)) { ptr.set(ptr.get(), ptr.getOffset(), getByteSize()); } super.coerceBytes(ptr, object, actualType, maxLength, scale, actualModifier, desiredMaxLength,