Repository: phoenix Updated Branches: refs/heads/4.x-HBase-1.2 f0af02259 -> a3bebbeb5
PHOENIX-4283 fix a coearceByte issue which causes nested group by big int incorrect Signed-off-by: aertoria <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/1fc5b270 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/1fc5b270 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/1fc5b270 Branch: refs/heads/4.x-HBase-1.2 Commit: 1fc5b2703b0f01cfca3abacabf20656485d651df Parents: f0af022 Author: aertoria <[email protected]> Authored: Sun Oct 15 18:36:44 2017 -0700 Committer: James Taylor <[email protected]> Committed: Wed Nov 15 09:53:44 2017 -0800 ---------------------------------------------------------------------- .../apache/phoenix/end2end/GroupByCaseIT.java | 63 ++++++++++++++++++++ .../org/apache/phoenix/schema/types/PLong.java | 3 +- 2 files changed, 65 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/1fc5b270/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByCaseIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByCaseIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByCaseIT.java index 6a0ac27..cc850b7 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByCaseIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByCaseIT.java @@ -928,6 +928,69 @@ public class GroupByCaseIT extends ParallelStatsDisabledIT { } } + @Test + public void testCountNullInEncodedNonEmptyKeyValueCF() throws Exception { + testCountNullInNonEmptyKeyValueCF(1); + } + + @Test + 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 + String intTableName=generateUniqueName(); + String sql="create table " + intTableName + " (mykey integer not null primary key, A.COLA integer, B.COLB integer) " + + "IMMUTABLE_ROWS=true, IMMUTABLE_STORAGE_SCHEME = ONE_CELL_PER_COLUMN, COLUMN_ENCODED_BYTES = " + columnEncodedBytes + ", DISABLE_WAL=true"; + + conn.createStatement().execute(sql); + conn.createStatement().execute("UPSERT INTO "+intTableName+" VALUES (1,1)"); + conn.createStatement().execute("UPSERT INTO "+intTableName+" VALUES (2,1)"); + conn.createStatement().execute("UPSERT INTO "+intTableName+" VALUES (3,1,2)"); + conn.createStatement().execute("UPSERT INTO "+intTableName+" VALUES (4,1)"); + conn.createStatement().execute("UPSERT INTO "+intTableName+" VALUES (5,1)"); + conn.commit(); + + TestUtil.dumpTable(conn.unwrap(PhoenixConnection.class).getQueryServices().getTable(Bytes.toBytes(intTableName))); + + sql="select count(*) from "+intTableName; + ResultSet rs=conn.createStatement().executeQuery(sql); + assertTrue(rs.next()); + assertEquals(5, rs.getInt(1)); + + sql="select count(*) from "+intTableName + " where b.colb is not null"; + rs=conn.createStatement().executeQuery(sql); + assertTrue(rs.next()); + assertEquals(1, rs.getInt(1)); + + sql="select count(*) from "+intTableName + " where b.colb is null"; + rs=conn.createStatement().executeQuery(sql); + assertTrue(rs.next()); + assertEquals(4, rs.getInt(1)); + } + } + private void assertResultSet(ResultSet rs,Object[][] rows) throws Exception { for(int rowIndex=0;rowIndex<rows.length;rowIndex++) { assertTrue(rs.next()); http://git-wip-us.apache.org/repos/asf/phoenix/blob/1fc5b270/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,
