Repository: phoenix Updated Branches: refs/heads/4.5-HBase-0.98 c1fadb10c -> 98b01546f
PHOENIX-2205 Group by a divided value (e.g., time/10) returns NULL Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/98b01546 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/98b01546 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/98b01546 Branch: refs/heads/4.5-HBase-0.98 Commit: 98b01546fd0c8a5437c0abda3ee786ea335c089a Parents: c1fadb1 Author: Dumindu Buddhika <dumin...@apache.org> Authored: Mon Sep 21 19:29:04 2015 +0530 Committer: Dumindu Buddhika <dumin...@apache.org> Committed: Mon Sep 21 19:29:04 2015 +0530 ---------------------------------------------------------------------- .../org/apache/phoenix/end2end/GroupByIT.java | 72 ++++++++++++++++++++ .../expression/RowKeyColumnExpression.java | 2 +- 2 files changed, 73 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/phoenix/blob/98b01546/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByIT.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByIT.java index 31a55a0..51ab070 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/GroupByIT.java @@ -574,4 +574,76 @@ public class GroupByIT extends BaseQueryIT { conn.close(); } + + @Test + public void testGroupByWithIntegerDivision1() throws Exception { + long ts = nextTimestamp(); + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10)); + Connection conn = DriverManager.getConnection(getUrl(), props); + String ddl = "create table test1(time integer not null, hostname varchar not null,usage float,period integer constraint pk PRIMARY KEY(time, hostname))"; + conn.createStatement().execute(ddl); + conn.close(); + + props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30)); + conn = DriverManager.getConnection(getUrl(), props); + PreparedStatement stmt = conn.prepareStatement("upsert into test1 values(1439853462,'qa9',8.27,1439853462)"); + stmt.execute(); + stmt = conn.prepareStatement("upsert into test1 values(1439853461,'qa9',8.27,1439853362)"); + stmt.execute(); + stmt = conn.prepareStatement("upsert into test1 values(1439853461,'qa9',5.27,1439853461)"); + stmt.execute(); + stmt = conn.prepareStatement("upsert into test1 values(1439853451,'qa9',4.27,1439853451)"); + stmt.execute(); + conn.commit(); + conn.close(); + + props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40)); + conn = DriverManager.getConnection(getUrl(), props); + ResultSet rs; + stmt = conn.prepareStatement("select time/10 as tm, hostname, avg(usage) from test1 group by hostname, tm"); + rs = stmt.executeQuery(); + assertTrue(rs.next()); + assertEquals(143985345, rs.getInt(1)); + assertEquals(4.2699, rs.getDouble(3), 0.1); + assertTrue(rs.next()); + assertEquals(143985346, rs.getInt(1)); + assertEquals(6.77, rs.getDouble(3), 0.1); + } + + @Test + public void testGroupByWithIntegerDivision2() throws Exception { + long ts = nextTimestamp(); + Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES); + props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 10)); + Connection conn = DriverManager.getConnection(getUrl(), props); + String ddl = "create table test1(time integer not null, hostname varchar not null,usage float,period integer constraint pk PRIMARY KEY(time, hostname))"; + conn.createStatement().execute(ddl); + conn.close(); + + props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 30)); + conn = DriverManager.getConnection(getUrl(), props); + PreparedStatement stmt = conn.prepareStatement("upsert into test1 values(1439853462,'qa9',8.27,1439853462)"); + stmt.execute(); + stmt = conn.prepareStatement("upsert into test1 values(1439853461,'qa9',8.27,1439853362)"); + stmt.execute(); + stmt = conn.prepareStatement("upsert into test1 values(1439853461,'qa9',5.27,1439853461)"); + stmt.execute(); + stmt = conn.prepareStatement("upsert into test1 values(1439853451,'qa9',4.27,1439853451)"); + stmt.execute(); + conn.commit(); + conn.close(); + + props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(ts + 40)); + conn = DriverManager.getConnection(getUrl(), props); + ResultSet rs; + stmt = conn.prepareStatement("select period/10 as tm, hostname, avg(usage) from test1 group by hostname, tm"); + rs = stmt.executeQuery(); + assertTrue(rs.next()); + assertEquals(143985345, rs.getInt(1)); + assertEquals(4.2699, rs.getDouble(3), 0.1); + assertTrue(rs.next()); + assertEquals(143985346, rs.getInt(1)); + assertEquals(6.77, rs.getDouble(3), 0.1); + } } http://git-wip-us.apache.org/repos/asf/phoenix/blob/98b01546/phoenix-core/src/main/java/org/apache/phoenix/expression/RowKeyColumnExpression.java ---------------------------------------------------------------------- diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/RowKeyColumnExpression.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowKeyColumnExpression.java index e4ec438..03cc51f 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/expression/RowKeyColumnExpression.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowKeyColumnExpression.java @@ -118,7 +118,7 @@ public class RowKeyColumnExpression extends ColumnExpression { // FIXME: fixedByteSize <= maxByteSize ? fixedByteSize : 0 required because HBase passes bogus keys to filter to position scan (HBASE-6562) if (fromType.isFixedWidth()) { Integer maxLength = getMaxLength(); - byteSize = maxLength == null ? fromType.getByteSize() : maxLength; + byteSize = fromType.getByteSize() == null ? maxLength : fromType.getByteSize(); byteSize = byteSize <= maxOffset ? byteSize : 0; } int length = byteSize >= 0 ? byteSize : accessor.getLength(buffer, offset, maxOffset);