Repository: phoenix
Updated Branches:
  refs/heads/master ff8055553 -> bab06d688


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

Branch: refs/heads/master
Commit: bab06d688acde9801ae171420f94871b8e78684f
Parents: ff80555
Author: aertoria <casti...@gmail.com>
Authored: Sun Oct 15 18:36:44 2017 -0700
Committer: aertoria <casti...@gmail.com>
Committed: Mon Oct 16 11:13:34 2017 -0700

----------------------------------------------------------------------
 .../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/bab06d68/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 bde9b9d..09e51c5 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
@@ -939,7 +939,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/bab06d68/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,

Reply via email to