phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dumin...@apache.org
Subject phoenix git commit: PHOENIX-2205 Group by a divided value (e.g., time/10) returns NULL
Date Mon, 21 Sep 2015 13:24:27 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 6cd79361c -> 1f4a5400b


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

Branch: refs/heads/4.x-HBase-0.98
Commit: 1f4a5400b21289216454fc11285f5c785cc4cffe
Parents: 6cd7936
Author: Dumindu Buddhika <duminduk@apache.org>
Authored: Mon Sep 21 18:52:34 2015 +0530
Committer: Dumindu Buddhika <duminduk@apache.org>
Committed: Mon Sep 21 18:52:34 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/1f4a5400/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/1f4a5400/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);


Mime
View raw message