git commit: PHOENIX-1332 Support correlated subqueries in comparison with ANY/SOME/ALL

2014-10-13 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/master 656acefd1 - 49ec34be2


PHOENIX-1332 Support correlated subqueries in comparison with ANY/SOME/ALL


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

Branch: refs/heads/master
Commit: 49ec34be258ce12ca150c5c37a35e2c1cad0105c
Parents: 656acef
Author: maryannxue maryann...@apache.org
Authored: Mon Oct 13 11:05:00 2014 -0400
Committer: maryannxue maryann...@apache.org
Committed: Mon Oct 13 11:05:00 2014 -0400

--
 .../org/apache/phoenix/end2end/SubqueryIT.java  |  79 
 .../org/apache/phoenix/cache/HashCache.java |   4 +-
 .../apache/phoenix/compile/JoinCompiler.java|  15 +-
 .../apache/phoenix/compile/QueryCompiler.java   |   4 +-
 .../phoenix/compile/SubqueryRewriter.java   | 181 +++
 .../coprocessor/HashJoinRegionScanner.java  |   1 +
 .../apache/phoenix/execute/HashJoinPlan.java|   5 +-
 .../expression/ArrayConstructorExpression.java  |  16 +-
 .../phoenix/expression/ExpressionType.java  |   2 +
 .../DistinctValueClientAggregator.java  |  63 +++
 .../DistinctValueWithCountServerAggregator.java |   2 +-
 .../DistinctValueAggregateFunction.java |  66 +++
 .../apache/phoenix/join/HashCacheClient.java|   7 +-
 .../apache/phoenix/join/HashCacheFactory.java   |  15 +-
 .../org/apache/phoenix/parse/JoinTableNode.java |   8 +-
 .../apache/phoenix/parse/ParseNodeFactory.java  |   6 +-
 .../apache/phoenix/parse/ParseNodeRewriter.java |   2 +-
 17 files changed, 417 insertions(+), 59 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/49ec34be/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryIT.java
index 58d92f3..e4b4c8b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryIT.java
@@ -899,6 +899,85 @@ public class SubqueryIT extends BaseHBaseManagedTimeIT {
 rs = conn.createStatement().executeQuery(EXPLAIN  + query);
 String plan = QueryUtil.getExplainPlan(rs);
 assertTrue(\ + plan + \ does not match \ + plans[4] + \, 
Pattern.matches(plans[4], plan));
+
+query = SELECT \order_id\ FROM  + JOIN_ORDER_TABLE_FULL_NAME + 
 o WHERE quantity = (SELECT quantity FROM  + JOIN_ORDER_TABLE_FULL_NAME +  
WHERE o.\item_id\ = \item_id\ AND \order_id\ != '004');
+statement = conn.prepareStatement(query);
+rs = statement.executeQuery();
+assertTrue (rs.next());
+assertEquals(rs.getString(1), 001);
+assertTrue (rs.next());
+assertEquals(rs.getString(1), 002);
+assertTrue (rs.next());
+assertEquals(rs.getString(1), 003);
+assertTrue (rs.next());
+assertEquals(rs.getString(1), 005);
+
+assertFalse(rs.next());
+
+query = SELECT \order_id\ FROM  + JOIN_ORDER_TABLE_FULL_NAME + 
 o WHERE quantity = (SELECT quantity FROM  + JOIN_ORDER_TABLE_FULL_NAME +  
WHERE o.\item_id\ = \item_id\ AND \order_id\ != '003');
+statement = conn.prepareStatement(query);
+rs = statement.executeQuery();
+try {
+while(rs.next());
+fail(Should have got exception.);
+} catch (SQLException e) {
+}
+
+query = SELECT \order_id\ FROM  + JOIN_ORDER_TABLE_FULL_NAME + 
 o WHERE quantity = (SELECT max(quantity) FROM  + JOIN_ORDER_TABLE_FULL_NAME 
+  WHERE o.\item_id\ = \item_id\ AND \order_id\ != '004' 
GROUP BY \order_id\);
+statement = conn.prepareStatement(query);
+rs = statement.executeQuery();
+assertTrue (rs.next());
+assertEquals(rs.getString(1), 001);
+assertTrue (rs.next());
+assertEquals(rs.getString(1), 002);
+assertTrue (rs.next());
+assertEquals(rs.getString(1), 003);
+assertTrue (rs.next());
+assertEquals(rs.getString(1), 005);
+
+assertFalse(rs.next());
+
+query = SELECT \order_id\ FROM  + JOIN_ORDER_TABLE_FULL_NAME + 
 o WHERE quantity = (SELECT max(quantity) FROM  + JOIN_ORDER_TABLE_FULL_NAME 
+  WHERE o.\item_id\ = \item_id\ AND \order_id\ != 

git commit: PHOENIX-1332 Support correlated subqueries in comparison with ANY/SOME/ALL

2014-10-13 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/3.0 8c37ab471 - cc436c9b4


PHOENIX-1332 Support correlated subqueries in comparison with ANY/SOME/ALL


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

Branch: refs/heads/3.0
Commit: cc436c9b43c48d636d0659cdb29618e957275111
Parents: 8c37ab4
Author: maryannxue maryann...@apache.org
Authored: Mon Oct 13 11:25:43 2014 -0400
Committer: maryannxue maryann...@apache.org
Committed: Mon Oct 13 11:25:43 2014 -0400

--
 .../org/apache/phoenix/end2end/SubqueryIT.java  |  79 
 .../org/apache/phoenix/cache/HashCache.java |   4 +-
 .../apache/phoenix/compile/JoinCompiler.java|  15 +-
 .../apache/phoenix/compile/QueryCompiler.java   |   4 +-
 .../phoenix/compile/SubqueryRewriter.java   | 181 +++
 .../coprocessor/HashJoinRegionScanner.java  |   1 +
 .../apache/phoenix/execute/HashJoinPlan.java|   5 +-
 .../expression/ArrayConstructorExpression.java  |  16 +-
 .../phoenix/expression/ExpressionType.java  |   2 +
 .../DistinctValueClientAggregator.java  |  63 +++
 .../DistinctValueWithCountServerAggregator.java |   2 +-
 .../DistinctValueAggregateFunction.java |  66 +++
 .../apache/phoenix/join/HashCacheClient.java|   7 +-
 .../apache/phoenix/join/HashCacheFactory.java   |  14 +-
 .../org/apache/phoenix/parse/JoinTableNode.java |   8 +-
 .../apache/phoenix/parse/ParseNodeFactory.java  |   6 +-
 .../apache/phoenix/parse/ParseNodeRewriter.java |   2 +-
 17 files changed, 417 insertions(+), 58 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/cc436c9b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryIT.java
index 61ab788..f0b8cc1 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SubqueryIT.java
@@ -822,6 +822,85 @@ public class SubqueryIT extends BaseHBaseManagedTimeIT {
 rs = conn.createStatement().executeQuery(EXPLAIN  + query);
 String plan = QueryUtil.getExplainPlan(rs);
 assertTrue(\ + plan + \ does not match \ + plans[4] + \, 
Pattern.matches(plans[4], plan));
+
+query = SELECT \order_id\ FROM  + JOIN_ORDER_TABLE_FULL_NAME + 
 o WHERE quantity = (SELECT quantity FROM  + JOIN_ORDER_TABLE_FULL_NAME +  
WHERE o.\item_id\ = \item_id\ AND \order_id\ != '004');
+statement = conn.prepareStatement(query);
+rs = statement.executeQuery();
+assertTrue (rs.next());
+assertEquals(rs.getString(1), 001);
+assertTrue (rs.next());
+assertEquals(rs.getString(1), 002);
+assertTrue (rs.next());
+assertEquals(rs.getString(1), 003);
+assertTrue (rs.next());
+assertEquals(rs.getString(1), 005);
+
+assertFalse(rs.next());
+
+query = SELECT \order_id\ FROM  + JOIN_ORDER_TABLE_FULL_NAME + 
 o WHERE quantity = (SELECT quantity FROM  + JOIN_ORDER_TABLE_FULL_NAME +  
WHERE o.\item_id\ = \item_id\ AND \order_id\ != '003');
+statement = conn.prepareStatement(query);
+rs = statement.executeQuery();
+try {
+while(rs.next());
+fail(Should have got exception.);
+} catch (SQLException e) {
+}
+
+query = SELECT \order_id\ FROM  + JOIN_ORDER_TABLE_FULL_NAME + 
 o WHERE quantity = (SELECT max(quantity) FROM  + JOIN_ORDER_TABLE_FULL_NAME 
+  WHERE o.\item_id\ = \item_id\ AND \order_id\ != '004' 
GROUP BY \order_id\);
+statement = conn.prepareStatement(query);
+rs = statement.executeQuery();
+assertTrue (rs.next());
+assertEquals(rs.getString(1), 001);
+assertTrue (rs.next());
+assertEquals(rs.getString(1), 002);
+assertTrue (rs.next());
+assertEquals(rs.getString(1), 003);
+assertTrue (rs.next());
+assertEquals(rs.getString(1), 005);
+
+assertFalse(rs.next());
+
+query = SELECT \order_id\ FROM  + JOIN_ORDER_TABLE_FULL_NAME + 
 o WHERE quantity = (SELECT max(quantity) FROM  + JOIN_ORDER_TABLE_FULL_NAME 
+  WHERE o.\item_id\ = \item_id\ AND \order_id\ != '003'