You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ew...@apache.org on 2017/10/16 18:21:20 UTC

phoenix git commit: PHOENIX-4283 fix a coearceByte issue which causes nested group by big int incorrect

Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 fe8c738e4 -> a9d724216


PHOENIX-4283 fix a coearceByte issue which causes nested group by big int incorrect

Signed-off-by: aertoria <ca...@gmail.com>


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

Branch: refs/heads/4.x-HBase-0.98
Commit: a9d724216d2c3d3384bf10a28934abdd52550c6f
Parents: fe8c738
Author: aertoria <ca...@gmail.com>
Authored: Sun Oct 15 18:36:44 2017 -0700
Committer: aertoria <ca...@gmail.com>
Committed: Mon Oct 16 11:18:58 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/a9d72421/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/a9d72421/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,