You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by td...@apache.org on 2017/05/24 19:34:32 UTC
phoenix git commit: PHOENIX-3879 UNION ALL with subqueries that have
aggregate functions on fixed length columns throw an NPE
Repository: phoenix
Updated Branches:
refs/heads/master 2398f7844 -> 5f9cf15e2
PHOENIX-3879 UNION ALL with subqueries that have aggregate functions on fixed length columns throw an NPE
Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/5f9cf15e
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/5f9cf15e
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/5f9cf15e
Branch: refs/heads/master
Commit: 5f9cf15e272fc9d92a3165753ac2157396851bd6
Parents: 2398f78
Author: Thomas <td...@salesforce.com>
Authored: Tue May 23 13:08:28 2017 -0700
Committer: Thomas <td...@salesforce.com>
Committed: Wed May 24 12:34:04 2017 -0700
----------------------------------------------------------------------
.../phoenix/end2end/NthValueFunctionIT.java | 55 ++++++++++++++++++++
.../function/FirstLastValueBaseFunction.java | 10 ++++
2 files changed, 65 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/phoenix/blob/5f9cf15e/phoenix-core/src/it/java/org/apache/phoenix/end2end/NthValueFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/NthValueFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/NthValueFunctionIT.java
index 80da494..0f6bf25 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/NthValueFunctionIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/NthValueFunctionIT.java
@@ -487,5 +487,60 @@ public class NthValueFunctionIT extends ParallelStatsDisabledIT {
}
assertTrue(shouldList.contains(actualValue));
}
+
+ @Test
+ public void testUnionAll() throws Exception {
+ Connection conn = DriverManager.getConnection(getUrl());
+
+ String nthValue = generateUniqueName();
+ String ddl = "CREATE TABLE IF NOT EXISTS " + nthValue + " "
+ + "(id INTEGER NOT NULL, feid UNSIGNED_LONG NOT NULL,"
+ + " uid CHAR(1) NOT NULL, lrd INTEGER"
+ + " CONSTRAINT PKVIEW PRIMARY KEY ( id, feid, uid))";
+ conn.createStatement().execute(ddl);
+
+ conn.createStatement().execute(
+ "UPSERT INTO " + nthValue + " (id, feid, uid, lrd) VALUES (2, 8, '1', 7)");
+ conn.createStatement().execute(
+ "UPSERT INTO " + nthValue + " (id, feid, uid, lrd) VALUES (2, 8, '2', 9)");
+ conn.createStatement().execute(
+ "UPSERT INTO " + nthValue + " (id, feid, uid, lrd) VALUES (2, 8, '3', 4)");
+ conn.createStatement().execute(
+ "UPSERT INTO " + nthValue + " (id, feid, uid, lrd) VALUES (2, 8, '4', 2)");
+ conn.createStatement().execute(
+ "UPSERT INTO " + nthValue + " (id, feid, uid, lrd) VALUES (2, 9, '5', 1)");
+ conn.createStatement().execute(
+ "UPSERT INTO " + nthValue + " (id, feid, uid, lrd) VALUES (2, 9, '6', 3)");
+ conn.createStatement().execute(
+ "UPSERT INTO " + nthValue + " (id, feid, uid, lrd) VALUES (2, 9, '8', 5)");
+ conn.createStatement().execute(
+ "UPSERT INTO " + nthValue + " (id, feid, uid, lrd) VALUES (2, 9, '7', 8)");
+ conn.commit();
+
+ ResultSet rs = conn.createStatement().executeQuery(
+ "SELECT feid, NTH_VALUE(uid, 1) WITHIN GROUP (ORDER BY lrd DESC) as user_id, NTH_VALUE(lrd, 1) WITHIN GROUP (ORDER BY lrd DESC) as lrd FROM " + nthValue
+ + " where id=2 and feid in (8, 9) GROUP BY feid"
+ + " UNION ALL"
+ + " SELECT feid, NTH_VALUE(uid, 2) WITHIN GROUP (ORDER BY lrd DESC) as user_id, NTH_VALUE(lrd, 2) WITHIN GROUP (ORDER BY lrd DESC) as lrd FROM " + nthValue
+ + " where id=2 and feid in (8, 9) GROUP BY feid");
+
+ assertTrue(rs.next());
+ assertEquals(8, rs.getInt(1));
+ assertEquals("2", rs.getString(2));
+ assertEquals(9, rs.getInt(3));
+ assertTrue(rs.next());
+ assertEquals(9, rs.getInt(1));
+ assertEquals("7", rs.getString(2));
+ assertEquals(8, rs.getInt(3));
+ assertTrue(rs.next());
+ assertEquals(8, rs.getInt(1));
+ assertEquals("1", rs.getString(2));
+ assertEquals(7, rs.getInt(3));
+ assertTrue(rs.next());
+ assertEquals(9, rs.getInt(1));
+ assertEquals("8", rs.getString(2));
+ assertEquals(5, rs.getInt(3));
+ assertFalse(rs.next());
+ }
}
http://git-wip-us.apache.org/repos/asf/phoenix/blob/5f9cf15e/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FirstLastValueBaseFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FirstLastValueBaseFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FirstLastValueBaseFunction.java
index 497122e..61a196d 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FirstLastValueBaseFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/FirstLastValueBaseFunction.java
@@ -53,4 +53,14 @@ abstract public class FirstLastValueBaseFunction extends DelegateConstantToCount
public PDataType getDataType() {
return children.get(2).getDataType();
}
+
+ @Override
+ public Integer getMaxLength() {
+ return children.get(2).getMaxLength();
+ }
+
+ @Override
+ public Integer getScale() {
+ return children.get(2).getScale();
+ }
}