git commit: PHOENIX-1182 UPSERT SELECT not working with joins; Add a test in DerivedTableIT

2014-08-19 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/3.0 05eb9a668 - 4b511a0c4


PHOENIX-1182 UPSERT SELECT not working with joins; Add a test in DerivedTableIT


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

Branch: refs/heads/3.0
Commit: 4b511a0c4a20cd8b2c95ecc73b34f6d970035983
Parents: 05eb9a6
Author: maryannxue maryann...@apache.org
Authored: Tue Aug 19 16:15:30 2014 -0400
Committer: maryannxue maryann...@apache.org
Committed: Tue Aug 19 16:15:30 2014 -0400

--
 .../apache/phoenix/end2end/DerivedTableIT.java  | 13 ++
 .../org/apache/phoenix/end2end/HashJoinIT.java  | 49 
 .../apache/phoenix/compile/QueryCompiler.java   | 13 +++---
 3 files changed, 69 insertions(+), 6 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/4b511a0c/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java
index 2e45313..8a80764 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java
@@ -395,6 +395,19 @@ public class DerivedTableIT extends 
BaseClientManagedTimeIT {
 } catch (SQLFeatureNotSupportedException e) {
 assertEquals(MSG, e.getMessage());
 }
+
+// (groupby orderby) limit
+query = SELECT a, s FROM (SELECT a_string a, sum(a_byte) s FROM 
aTable GROUP BY a_string ORDER BY sum(a_byte)) LIMIT 2;
+statement = conn.prepareStatement(query);
+rs = statement.executeQuery();
+assertTrue (rs.next());
+assertEquals(C_VALUE,rs.getString(1));
+assertEquals(9,rs.getInt(2));
+assertTrue (rs.next());
+assertEquals(A_VALUE,rs.getString(1));
+assertEquals(10,rs.getInt(2));
+
+assertFalse(rs.next());
 } finally {
 conn.close();
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4b511a0c/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinIT.java
index 02caa9d..d5f1297 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinIT.java
@@ -2530,6 +2530,55 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
 assertNull(rs.getDate(5));
 
 assertFalse(rs.next());
+
+//Bug: PHOENIX-1182
+String sourceTable = SOURCE_TABLE;
+String joinTable = JOIN_TABLE;
+conn.createStatement().execute(CREATE TABLE  + sourceTable 
++(TID CHAR(3) NOT NULL, 
++ A UNSIGNED_INT NOT NULL,  
++ B UNSIGNED_INT NOT NULL 
++ CONSTRAINT pk PRIMARY KEY (TID, A, B)));
+conn.createStatement().execute(CREATE TABLE  + joinTable 
++(TID CHAR(3) NOT NULL, 
++ A UNSIGNED_INT NOT NULL, 
++ B UNSIGNED_INT NOT NULL, 
++ COUNT UNSIGNED_INT 
++ CONSTRAINT pk PRIMARY KEY (TID, A, B)));
+
+PreparedStatement upsertStmt = conn.prepareStatement(
+upsert into  + sourceTable + (TID, A, B)  + values 
(?, ?, ?));
+upsertStmt.setString(1, 1);
+upsertStmt.setInt(2, 1);
+upsertStmt.setInt(3, 1);
+upsertStmt.execute();
+upsertStmt.setString(1, 1);
+upsertStmt.setInt(2, 1);
+upsertStmt.setInt(3, 2);
+upsertStmt.execute();
+upsertStmt.setString(1, 1);
+upsertStmt.setInt(2, 1);
+upsertStmt.setInt(3, 3);
+upsertStmt.execute();
+upsertStmt.setString(1, 1);
+upsertStmt.setInt(2, 2);
+upsertStmt.setInt(3, 1);
+upsertStmt.execute();
+upsertStmt.setString(1, 1);
+upsertStmt.setInt(2, 2);
+upsertStmt.setInt(3, 2);
+upsertStmt.execute();
+conn.commit();
+
+upsertStmt = conn.prepareStatement(
+   

git commit: PHOENIX-1182 UPSERT SELECT not working with joins; Add a test in DerivedTableIT

2014-08-19 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.0 0420b013d - 9973c1ac6


PHOENIX-1182 UPSERT SELECT not working with joins; Add a test in DerivedTableIT


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

Branch: refs/heads/4.0
Commit: 9973c1ac6db6acac172e66abf1651a839e64788c
Parents: 0420b01
Author: maryannxue maryann...@apache.org
Authored: Tue Aug 19 16:19:16 2014 -0400
Committer: maryannxue maryann...@apache.org
Committed: Tue Aug 19 16:19:16 2014 -0400

--
 .../apache/phoenix/end2end/DerivedTableIT.java  | 13 ++
 .../org/apache/phoenix/end2end/HashJoinIT.java  | 49 
 .../apache/phoenix/compile/QueryCompiler.java   | 13 +++---
 3 files changed, 69 insertions(+), 6 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/9973c1ac/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java
index 2e45313..8a80764 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DerivedTableIT.java
@@ -395,6 +395,19 @@ public class DerivedTableIT extends 
BaseClientManagedTimeIT {
 } catch (SQLFeatureNotSupportedException e) {
 assertEquals(MSG, e.getMessage());
 }
+
+// (groupby orderby) limit
+query = SELECT a, s FROM (SELECT a_string a, sum(a_byte) s FROM 
aTable GROUP BY a_string ORDER BY sum(a_byte)) LIMIT 2;
+statement = conn.prepareStatement(query);
+rs = statement.executeQuery();
+assertTrue (rs.next());
+assertEquals(C_VALUE,rs.getString(1));
+assertEquals(9,rs.getInt(2));
+assertTrue (rs.next());
+assertEquals(A_VALUE,rs.getString(1));
+assertEquals(10,rs.getInt(2));
+
+assertFalse(rs.next());
 } finally {
 conn.close();
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9973c1ac/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinIT.java
index e880253..65ebaa6 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/HashJoinIT.java
@@ -2889,6 +2889,55 @@ public class HashJoinIT extends BaseHBaseManagedTimeIT {
 assertNull(rs.getDate(5));
 
 assertFalse(rs.next());
+
+//Bug: PHOENIX-1182
+String sourceTable = SOURCE_TABLE;
+String joinTable = JOIN_TABLE;
+conn.createStatement().execute(CREATE TABLE  + sourceTable 
++(TID CHAR(3) NOT NULL, 
++ A UNSIGNED_INT NOT NULL,  
++ B UNSIGNED_INT NOT NULL 
++ CONSTRAINT pk PRIMARY KEY (TID, A, B)));
+conn.createStatement().execute(CREATE TABLE  + joinTable 
++(TID CHAR(3) NOT NULL, 
++ A UNSIGNED_INT NOT NULL, 
++ B UNSIGNED_INT NOT NULL, 
++ COUNT UNSIGNED_INT 
++ CONSTRAINT pk PRIMARY KEY (TID, A, B)));
+
+PreparedStatement upsertStmt = conn.prepareStatement(
+upsert into  + sourceTable + (TID, A, B)  + values 
(?, ?, ?));
+upsertStmt.setString(1, 1);
+upsertStmt.setInt(2, 1);
+upsertStmt.setInt(3, 1);
+upsertStmt.execute();
+upsertStmt.setString(1, 1);
+upsertStmt.setInt(2, 1);
+upsertStmt.setInt(3, 2);
+upsertStmt.execute();
+upsertStmt.setString(1, 1);
+upsertStmt.setInt(2, 1);
+upsertStmt.setInt(3, 3);
+upsertStmt.execute();
+upsertStmt.setString(1, 1);
+upsertStmt.setInt(2, 2);
+upsertStmt.setInt(3, 1);
+upsertStmt.execute();
+upsertStmt.setString(1, 1);
+upsertStmt.setInt(2, 2);
+upsertStmt.setInt(3, 2);
+upsertStmt.execute();
+conn.commit();
+
+upsertStmt = conn.prepareStatement(
+