phoenix git commit: PHOENIX-4692 ArrayIndexOutOfBoundsException in ScanRanges.intersectScan

2018-05-21 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-cdh5.11 c2d6bc17a -> 574d8188a


PHOENIX-4692 ArrayIndexOutOfBoundsException in ScanRanges.intersectScan


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

Branch: refs/heads/4.x-cdh5.11
Commit: 574d8188af859dc2d0467b681c7b88bd83f27dda
Parents: c2d6bc1
Author: maryannxue <maryann@gmail.com>
Authored: Mon May 21 11:17:46 2018 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Mon May 21 11:17:46 2018 -0700

--
 .../apache/phoenix/end2end/SkipScanQueryIT.java | 21 
 .../apache/phoenix/compile/WhereCompiler.java   | 12 +--
 .../apache/phoenix/execute/BaseQueryPlan.java   |  2 +-
 .../apache/phoenix/execute/HashJoinPlan.java|  5 -
 4 files changed, 32 insertions(+), 8 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/574d8188/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
index d98bbe2..fb0b568 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
@@ -563,4 +563,25 @@ public class SkipScanQueryIT extends 
ParallelStatsDisabledIT {
 assertFalse(rs.next());
 }
 }
+
+@Test
+public void testSkipScanJoinOptimization() throws Exception {
+try (Connection conn = DriverManager.getConnection(getUrl())) {
+String tableName = generateUniqueName();
+String viewName = generateUniqueName();
+String idxName = "IDX_" + tableName;
+conn.setAutoCommit(true);
+conn.createStatement().execute(
+"create table " + tableName + " (PK1 INTEGER NOT NULL, PK2 
INTEGER NOT NULL, " +
+" ID1 INTEGER, ID2 INTEGER CONSTRAINT PK PRIMARY 
KEY(PK1 , PK2))SALT_BUCKETS = 4");
+conn.createStatement().execute("upsert into " + tableName + " 
values (1,1,1,1)");
+conn.createStatement().execute("upsert into " + tableName + " 
values (2,2,2,2)");
+conn.createStatement().execute("upsert into " + tableName + " 
values (2,3,1,2)");
+conn.createStatement().execute("create view " + viewName + " as 
select * from " +
+tableName + " where PK1 in (1,2)");
+conn.createStatement().execute("create index " + idxName + " on " 
+ viewName + " (ID1)");
+ResultSet rs = conn.createStatement().executeQuery("select /*+ 
INDEX(" + viewName + " " + idxName + ") */ * from " + viewName + " where ID1 = 
1 ");
+assertTrue(rs.next());
+}
+}
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/574d8188/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
index 2cf5857..832b1f0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
@@ -105,9 +105,9 @@ public class WhereCompiler {
  * @throws AmbiguousColumnException if an unaliased column name is 
ambiguous across multiple tables
  */
 public static Expression compile(StatementContext context, 
FilterableStatement statement, ParseNode viewWhere, Set 
subqueryNodes) throws SQLException {
-return compile(context, statement, viewWhere, 
Collections.emptyList(), false, subqueryNodes);
+return compile(context, statement, viewWhere, 
Collections.emptyList(), subqueryNodes);
 }
-
+
 /**
  * Optimize scan ranges by applying dynamically generated filter 
expressions.
  * @param context the shared context during query compilation
@@ -118,7 +118,7 @@ public class WhereCompiler {
  * @throws ColumnNotFoundException if column name could not be resolved
  * @throws AmbiguousColumnException if an unaliased column name is 
ambiguous across multiple tables
  */
-public static Expression compile(StatementContext con

phoenix git commit: PHOENIX-4692 ArrayIndexOutOfBoundsException in ScanRanges.intersectScan

2018-05-21 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-cdh5.12 acde89ffb -> ef5e6112a


PHOENIX-4692 ArrayIndexOutOfBoundsException in ScanRanges.intersectScan


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

Branch: refs/heads/4.x-cdh5.12
Commit: ef5e6112a7d821189055bb6639e0dd8f65107ab9
Parents: acde89f
Author: maryannxue <maryann@gmail.com>
Authored: Mon May 21 11:16:19 2018 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Mon May 21 11:16:19 2018 -0700

--
 .../apache/phoenix/end2end/SkipScanQueryIT.java | 21 
 .../apache/phoenix/compile/WhereCompiler.java   | 12 +--
 .../apache/phoenix/execute/BaseQueryPlan.java   |  2 +-
 .../apache/phoenix/execute/HashJoinPlan.java|  5 -
 4 files changed, 32 insertions(+), 8 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/ef5e6112/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
index d98bbe2..fb0b568 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
@@ -563,4 +563,25 @@ public class SkipScanQueryIT extends 
ParallelStatsDisabledIT {
 assertFalse(rs.next());
 }
 }
+
+@Test
+public void testSkipScanJoinOptimization() throws Exception {
+try (Connection conn = DriverManager.getConnection(getUrl())) {
+String tableName = generateUniqueName();
+String viewName = generateUniqueName();
+String idxName = "IDX_" + tableName;
+conn.setAutoCommit(true);
+conn.createStatement().execute(
+"create table " + tableName + " (PK1 INTEGER NOT NULL, PK2 
INTEGER NOT NULL, " +
+" ID1 INTEGER, ID2 INTEGER CONSTRAINT PK PRIMARY 
KEY(PK1 , PK2))SALT_BUCKETS = 4");
+conn.createStatement().execute("upsert into " + tableName + " 
values (1,1,1,1)");
+conn.createStatement().execute("upsert into " + tableName + " 
values (2,2,2,2)");
+conn.createStatement().execute("upsert into " + tableName + " 
values (2,3,1,2)");
+conn.createStatement().execute("create view " + viewName + " as 
select * from " +
+tableName + " where PK1 in (1,2)");
+conn.createStatement().execute("create index " + idxName + " on " 
+ viewName + " (ID1)");
+ResultSet rs = conn.createStatement().executeQuery("select /*+ 
INDEX(" + viewName + " " + idxName + ") */ * from " + viewName + " where ID1 = 
1 ");
+assertTrue(rs.next());
+}
+}
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/ef5e6112/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
index 2cf5857..832b1f0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
@@ -105,9 +105,9 @@ public class WhereCompiler {
  * @throws AmbiguousColumnException if an unaliased column name is 
ambiguous across multiple tables
  */
 public static Expression compile(StatementContext context, 
FilterableStatement statement, ParseNode viewWhere, Set 
subqueryNodes) throws SQLException {
-return compile(context, statement, viewWhere, 
Collections.emptyList(), false, subqueryNodes);
+return compile(context, statement, viewWhere, 
Collections.emptyList(), subqueryNodes);
 }
-
+
 /**
  * Optimize scan ranges by applying dynamically generated filter 
expressions.
  * @param context the shared context during query compilation
@@ -118,7 +118,7 @@ public class WhereCompiler {
  * @throws ColumnNotFoundException if column name could not be resolved
  * @throws AmbiguousColumnException if an unaliased column name is 
ambiguous across multiple tables
  */
-public static Expression compile(StatementContext con

phoenix git commit: PHOENIX-4692 ArrayIndexOutOfBoundsException in ScanRanges.intersectScan

2018-05-21 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-cdh5.13 11a9b2472 -> f7211eaf7


PHOENIX-4692 ArrayIndexOutOfBoundsException in ScanRanges.intersectScan


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

Branch: refs/heads/4.x-cdh5.13
Commit: f7211eaf7d16c780b37df5a4d531d789d18dbcd7
Parents: 11a9b24
Author: maryannxue <maryann@gmail.com>
Authored: Mon May 21 11:13:59 2018 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Mon May 21 11:13:59 2018 -0700

--
 .../apache/phoenix/end2end/SkipScanQueryIT.java | 21 
 .../apache/phoenix/compile/WhereCompiler.java   | 12 +--
 .../apache/phoenix/execute/BaseQueryPlan.java   |  2 +-
 .../apache/phoenix/execute/HashJoinPlan.java|  5 -
 4 files changed, 32 insertions(+), 8 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/f7211eaf/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
index d98bbe2..fb0b568 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
@@ -563,4 +563,25 @@ public class SkipScanQueryIT extends 
ParallelStatsDisabledIT {
 assertFalse(rs.next());
 }
 }
+
+@Test
+public void testSkipScanJoinOptimization() throws Exception {
+try (Connection conn = DriverManager.getConnection(getUrl())) {
+String tableName = generateUniqueName();
+String viewName = generateUniqueName();
+String idxName = "IDX_" + tableName;
+conn.setAutoCommit(true);
+conn.createStatement().execute(
+"create table " + tableName + " (PK1 INTEGER NOT NULL, PK2 
INTEGER NOT NULL, " +
+" ID1 INTEGER, ID2 INTEGER CONSTRAINT PK PRIMARY 
KEY(PK1 , PK2))SALT_BUCKETS = 4");
+conn.createStatement().execute("upsert into " + tableName + " 
values (1,1,1,1)");
+conn.createStatement().execute("upsert into " + tableName + " 
values (2,2,2,2)");
+conn.createStatement().execute("upsert into " + tableName + " 
values (2,3,1,2)");
+conn.createStatement().execute("create view " + viewName + " as 
select * from " +
+tableName + " where PK1 in (1,2)");
+conn.createStatement().execute("create index " + idxName + " on " 
+ viewName + " (ID1)");
+ResultSet rs = conn.createStatement().executeQuery("select /*+ 
INDEX(" + viewName + " " + idxName + ") */ * from " + viewName + " where ID1 = 
1 ");
+assertTrue(rs.next());
+}
+}
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/f7211eaf/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
index 2cf5857..832b1f0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
@@ -105,9 +105,9 @@ public class WhereCompiler {
  * @throws AmbiguousColumnException if an unaliased column name is 
ambiguous across multiple tables
  */
 public static Expression compile(StatementContext context, 
FilterableStatement statement, ParseNode viewWhere, Set 
subqueryNodes) throws SQLException {
-return compile(context, statement, viewWhere, 
Collections.emptyList(), false, subqueryNodes);
+return compile(context, statement, viewWhere, 
Collections.emptyList(), subqueryNodes);
 }
-
+
 /**
  * Optimize scan ranges by applying dynamically generated filter 
expressions.
  * @param context the shared context during query compilation
@@ -118,7 +118,7 @@ public class WhereCompiler {
  * @throws ColumnNotFoundException if column name could not be resolved
  * @throws AmbiguousColumnException if an unaliased column name is 
ambiguous across multiple tables
  */
-public static Expression compile(StatementContext con

phoenix git commit: PHOENIX-4692 ArrayIndexOutOfBoundsException in ScanRanges.intersectScan

2018-05-21 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-cdh5.14 6d7bb2ed1 -> 07b6ad8c9


PHOENIX-4692 ArrayIndexOutOfBoundsException in ScanRanges.intersectScan


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

Branch: refs/heads/4.x-cdh5.14
Commit: 07b6ad8c92cc62ad9330d029021c393dffda7aac
Parents: 6d7bb2e
Author: maryannxue <maryann@gmail.com>
Authored: Mon May 21 11:11:53 2018 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Mon May 21 11:11:53 2018 -0700

--
 .../apache/phoenix/end2end/SkipScanQueryIT.java | 21 
 .../apache/phoenix/compile/WhereCompiler.java   | 12 +--
 .../apache/phoenix/execute/BaseQueryPlan.java   |  2 +-
 .../apache/phoenix/execute/HashJoinPlan.java|  5 -
 4 files changed, 32 insertions(+), 8 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/07b6ad8c/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
index d98bbe2..fb0b568 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
@@ -563,4 +563,25 @@ public class SkipScanQueryIT extends 
ParallelStatsDisabledIT {
 assertFalse(rs.next());
 }
 }
+
+@Test
+public void testSkipScanJoinOptimization() throws Exception {
+try (Connection conn = DriverManager.getConnection(getUrl())) {
+String tableName = generateUniqueName();
+String viewName = generateUniqueName();
+String idxName = "IDX_" + tableName;
+conn.setAutoCommit(true);
+conn.createStatement().execute(
+"create table " + tableName + " (PK1 INTEGER NOT NULL, PK2 
INTEGER NOT NULL, " +
+" ID1 INTEGER, ID2 INTEGER CONSTRAINT PK PRIMARY 
KEY(PK1 , PK2))SALT_BUCKETS = 4");
+conn.createStatement().execute("upsert into " + tableName + " 
values (1,1,1,1)");
+conn.createStatement().execute("upsert into " + tableName + " 
values (2,2,2,2)");
+conn.createStatement().execute("upsert into " + tableName + " 
values (2,3,1,2)");
+conn.createStatement().execute("create view " + viewName + " as 
select * from " +
+tableName + " where PK1 in (1,2)");
+conn.createStatement().execute("create index " + idxName + " on " 
+ viewName + " (ID1)");
+ResultSet rs = conn.createStatement().executeQuery("select /*+ 
INDEX(" + viewName + " " + idxName + ") */ * from " + viewName + " where ID1 = 
1 ");
+assertTrue(rs.next());
+}
+}
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/07b6ad8c/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
index 2cf5857..832b1f0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
@@ -105,9 +105,9 @@ public class WhereCompiler {
  * @throws AmbiguousColumnException if an unaliased column name is 
ambiguous across multiple tables
  */
 public static Expression compile(StatementContext context, 
FilterableStatement statement, ParseNode viewWhere, Set 
subqueryNodes) throws SQLException {
-return compile(context, statement, viewWhere, 
Collections.emptyList(), false, subqueryNodes);
+return compile(context, statement, viewWhere, 
Collections.emptyList(), subqueryNodes);
 }
-
+
 /**
  * Optimize scan ranges by applying dynamically generated filter 
expressions.
  * @param context the shared context during query compilation
@@ -118,7 +118,7 @@ public class WhereCompiler {
  * @throws ColumnNotFoundException if column name could not be resolved
  * @throws AmbiguousColumnException if an unaliased column name is 
ambiguous across multiple tables
  */
-public static Expression compile(StatementContext con

phoenix git commit: PHOENIX-4692 ArrayIndexOutOfBoundsException in ScanRanges.intersectScan

2018-05-21 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 2f35fe306 -> 097881c3f


PHOENIX-4692 ArrayIndexOutOfBoundsException in ScanRanges.intersectScan


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

Branch: refs/heads/4.x-HBase-0.98
Commit: 097881c3fad5bb746d2a58ae3f90d52d40121cfc
Parents: 2f35fe3
Author: maryannxue <maryann@gmail.com>
Authored: Mon May 21 11:07:52 2018 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Mon May 21 11:07:52 2018 -0700

--
 .../apache/phoenix/end2end/SkipScanQueryIT.java | 21 
 .../apache/phoenix/compile/WhereCompiler.java   | 12 +--
 .../apache/phoenix/execute/BaseQueryPlan.java   |  2 +-
 .../apache/phoenix/execute/HashJoinPlan.java|  5 -
 4 files changed, 32 insertions(+), 8 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/097881c3/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
index d98bbe2..fb0b568 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
@@ -563,4 +563,25 @@ public class SkipScanQueryIT extends 
ParallelStatsDisabledIT {
 assertFalse(rs.next());
 }
 }
+
+@Test
+public void testSkipScanJoinOptimization() throws Exception {
+try (Connection conn = DriverManager.getConnection(getUrl())) {
+String tableName = generateUniqueName();
+String viewName = generateUniqueName();
+String idxName = "IDX_" + tableName;
+conn.setAutoCommit(true);
+conn.createStatement().execute(
+"create table " + tableName + " (PK1 INTEGER NOT NULL, PK2 
INTEGER NOT NULL, " +
+" ID1 INTEGER, ID2 INTEGER CONSTRAINT PK PRIMARY 
KEY(PK1 , PK2))SALT_BUCKETS = 4");
+conn.createStatement().execute("upsert into " + tableName + " 
values (1,1,1,1)");
+conn.createStatement().execute("upsert into " + tableName + " 
values (2,2,2,2)");
+conn.createStatement().execute("upsert into " + tableName + " 
values (2,3,1,2)");
+conn.createStatement().execute("create view " + viewName + " as 
select * from " +
+tableName + " where PK1 in (1,2)");
+conn.createStatement().execute("create index " + idxName + " on " 
+ viewName + " (ID1)");
+ResultSet rs = conn.createStatement().executeQuery("select /*+ 
INDEX(" + viewName + " " + idxName + ") */ * from " + viewName + " where ID1 = 
1 ");
+assertTrue(rs.next());
+}
+}
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/097881c3/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
index 2cf5857..832b1f0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
@@ -105,9 +105,9 @@ public class WhereCompiler {
  * @throws AmbiguousColumnException if an unaliased column name is 
ambiguous across multiple tables
  */
 public static Expression compile(StatementContext context, 
FilterableStatement statement, ParseNode viewWhere, Set 
subqueryNodes) throws SQLException {
-return compile(context, statement, viewWhere, 
Collections.emptyList(), false, subqueryNodes);
+return compile(context, statement, viewWhere, 
Collections.emptyList(), subqueryNodes);
 }
-
+
 /**
  * Optimize scan ranges by applying dynamically generated filter 
expressions.
  * @param context the shared context during query compilation
@@ -118,7 +118,7 @@ public class WhereCompiler {
  * @throws ColumnNotFoundException if column name could not be resolved
  * @throws AmbiguousColumnException if an unaliased column name is 
ambiguous across multiple tables
  */
-public static Expression compile(StatementCon

phoenix git commit: PHOENIX-4692 ArrayIndexOutOfBoundsException in ScanRanges.intersectScan

2018-05-21 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.1 272a7e6bb -> e3b0579b2


PHOENIX-4692 ArrayIndexOutOfBoundsException in ScanRanges.intersectScan


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

Branch: refs/heads/4.x-HBase-1.1
Commit: e3b0579b21778c0303900e263f5d1e750c983804
Parents: 272a7e6
Author: maryannxue <maryann@gmail.com>
Authored: Mon May 21 11:05:45 2018 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Mon May 21 11:05:45 2018 -0700

--
 .../apache/phoenix/end2end/SkipScanQueryIT.java | 21 
 .../apache/phoenix/compile/WhereCompiler.java   | 12 +--
 .../apache/phoenix/execute/BaseQueryPlan.java   |  2 +-
 .../apache/phoenix/execute/HashJoinPlan.java|  5 -
 4 files changed, 32 insertions(+), 8 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/e3b0579b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
index d98bbe2..fb0b568 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
@@ -563,4 +563,25 @@ public class SkipScanQueryIT extends 
ParallelStatsDisabledIT {
 assertFalse(rs.next());
 }
 }
+
+@Test
+public void testSkipScanJoinOptimization() throws Exception {
+try (Connection conn = DriverManager.getConnection(getUrl())) {
+String tableName = generateUniqueName();
+String viewName = generateUniqueName();
+String idxName = "IDX_" + tableName;
+conn.setAutoCommit(true);
+conn.createStatement().execute(
+"create table " + tableName + " (PK1 INTEGER NOT NULL, PK2 
INTEGER NOT NULL, " +
+" ID1 INTEGER, ID2 INTEGER CONSTRAINT PK PRIMARY 
KEY(PK1 , PK2))SALT_BUCKETS = 4");
+conn.createStatement().execute("upsert into " + tableName + " 
values (1,1,1,1)");
+conn.createStatement().execute("upsert into " + tableName + " 
values (2,2,2,2)");
+conn.createStatement().execute("upsert into " + tableName + " 
values (2,3,1,2)");
+conn.createStatement().execute("create view " + viewName + " as 
select * from " +
+tableName + " where PK1 in (1,2)");
+conn.createStatement().execute("create index " + idxName + " on " 
+ viewName + " (ID1)");
+ResultSet rs = conn.createStatement().executeQuery("select /*+ 
INDEX(" + viewName + " " + idxName + ") */ * from " + viewName + " where ID1 = 
1 ");
+assertTrue(rs.next());
+}
+}
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e3b0579b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
index 2cf5857..832b1f0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
@@ -105,9 +105,9 @@ public class WhereCompiler {
  * @throws AmbiguousColumnException if an unaliased column name is 
ambiguous across multiple tables
  */
 public static Expression compile(StatementContext context, 
FilterableStatement statement, ParseNode viewWhere, Set 
subqueryNodes) throws SQLException {
-return compile(context, statement, viewWhere, 
Collections.emptyList(), false, subqueryNodes);
+return compile(context, statement, viewWhere, 
Collections.emptyList(), subqueryNodes);
 }
-
+
 /**
  * Optimize scan ranges by applying dynamically generated filter 
expressions.
  * @param context the shared context during query compilation
@@ -118,7 +118,7 @@ public class WhereCompiler {
  * @throws ColumnNotFoundException if column name could not be resolved
  * @throws AmbiguousColumnException if an unaliased column name is 
ambiguous across multiple tables
  */
-public static Expression compile(StatementCon

phoenix git commit: PHOENIX-4692 ArrayIndexOutOfBoundsException in ScanRanges.intersectScan

2018-05-21 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.2 8e012d013 -> eae096c28


PHOENIX-4692 ArrayIndexOutOfBoundsException in ScanRanges.intersectScan


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

Branch: refs/heads/4.x-HBase-1.2
Commit: eae096c288d3f174ba66214bf29c2c6e272db57d
Parents: 8e012d0
Author: maryannxue <maryann@gmail.com>
Authored: Mon May 21 10:19:30 2018 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Mon May 21 10:19:30 2018 -0700

--
 .../apache/phoenix/end2end/SkipScanQueryIT.java | 21 
 .../apache/phoenix/compile/WhereCompiler.java   | 12 +--
 .../apache/phoenix/execute/BaseQueryPlan.java   |  2 +-
 .../apache/phoenix/execute/HashJoinPlan.java|  5 -
 4 files changed, 32 insertions(+), 8 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/eae096c2/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
index d98bbe2..fb0b568 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
@@ -563,4 +563,25 @@ public class SkipScanQueryIT extends 
ParallelStatsDisabledIT {
 assertFalse(rs.next());
 }
 }
+
+@Test
+public void testSkipScanJoinOptimization() throws Exception {
+try (Connection conn = DriverManager.getConnection(getUrl())) {
+String tableName = generateUniqueName();
+String viewName = generateUniqueName();
+String idxName = "IDX_" + tableName;
+conn.setAutoCommit(true);
+conn.createStatement().execute(
+"create table " + tableName + " (PK1 INTEGER NOT NULL, PK2 
INTEGER NOT NULL, " +
+" ID1 INTEGER, ID2 INTEGER CONSTRAINT PK PRIMARY 
KEY(PK1 , PK2))SALT_BUCKETS = 4");
+conn.createStatement().execute("upsert into " + tableName + " 
values (1,1,1,1)");
+conn.createStatement().execute("upsert into " + tableName + " 
values (2,2,2,2)");
+conn.createStatement().execute("upsert into " + tableName + " 
values (2,3,1,2)");
+conn.createStatement().execute("create view " + viewName + " as 
select * from " +
+tableName + " where PK1 in (1,2)");
+conn.createStatement().execute("create index " + idxName + " on " 
+ viewName + " (ID1)");
+ResultSet rs = conn.createStatement().executeQuery("select /*+ 
INDEX(" + viewName + " " + idxName + ") */ * from " + viewName + " where ID1 = 
1 ");
+assertTrue(rs.next());
+}
+}
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/eae096c2/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
index 2cf5857..832b1f0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
@@ -105,9 +105,9 @@ public class WhereCompiler {
  * @throws AmbiguousColumnException if an unaliased column name is 
ambiguous across multiple tables
  */
 public static Expression compile(StatementContext context, 
FilterableStatement statement, ParseNode viewWhere, Set 
subqueryNodes) throws SQLException {
-return compile(context, statement, viewWhere, 
Collections.emptyList(), false, subqueryNodes);
+return compile(context, statement, viewWhere, 
Collections.emptyList(), subqueryNodes);
 }
-
+
 /**
  * Optimize scan ranges by applying dynamically generated filter 
expressions.
  * @param context the shared context during query compilation
@@ -118,7 +118,7 @@ public class WhereCompiler {
  * @throws ColumnNotFoundException if column name could not be resolved
  * @throws AmbiguousColumnException if an unaliased column name is 
ambiguous across multiple tables
  */
-public static Expression compile(StatementCon

phoenix git commit: PHOENIX-4692 ArrayIndexOutOfBoundsException in ScanRanges.intersectScan

2018-05-21 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.3 9066ce395 -> b11650082


PHOENIX-4692 ArrayIndexOutOfBoundsException in ScanRanges.intersectScan


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

Branch: refs/heads/4.x-HBase-1.3
Commit: b1165008230e212cfec1e52d86c6945176ad1d60
Parents: 9066ce3
Author: maryannxue <maryann@gmail.com>
Authored: Mon May 21 10:10:23 2018 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Mon May 21 10:10:23 2018 -0700

--
 .../apache/phoenix/end2end/SkipScanQueryIT.java | 21 
 .../apache/phoenix/compile/WhereCompiler.java   | 12 +--
 .../apache/phoenix/execute/BaseQueryPlan.java   |  2 +-
 .../apache/phoenix/execute/HashJoinPlan.java|  5 -
 4 files changed, 32 insertions(+), 8 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/b1165008/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
index d98bbe2..fb0b568 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
@@ -563,4 +563,25 @@ public class SkipScanQueryIT extends 
ParallelStatsDisabledIT {
 assertFalse(rs.next());
 }
 }
+
+@Test
+public void testSkipScanJoinOptimization() throws Exception {
+try (Connection conn = DriverManager.getConnection(getUrl())) {
+String tableName = generateUniqueName();
+String viewName = generateUniqueName();
+String idxName = "IDX_" + tableName;
+conn.setAutoCommit(true);
+conn.createStatement().execute(
+"create table " + tableName + " (PK1 INTEGER NOT NULL, PK2 
INTEGER NOT NULL, " +
+" ID1 INTEGER, ID2 INTEGER CONSTRAINT PK PRIMARY 
KEY(PK1 , PK2))SALT_BUCKETS = 4");
+conn.createStatement().execute("upsert into " + tableName + " 
values (1,1,1,1)");
+conn.createStatement().execute("upsert into " + tableName + " 
values (2,2,2,2)");
+conn.createStatement().execute("upsert into " + tableName + " 
values (2,3,1,2)");
+conn.createStatement().execute("create view " + viewName + " as 
select * from " +
+tableName + " where PK1 in (1,2)");
+conn.createStatement().execute("create index " + idxName + " on " 
+ viewName + " (ID1)");
+ResultSet rs = conn.createStatement().executeQuery("select /*+ 
INDEX(" + viewName + " " + idxName + ") */ * from " + viewName + " where ID1 = 
1 ");
+assertTrue(rs.next());
+}
+}
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b1165008/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
index 2cf5857..832b1f0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
@@ -105,9 +105,9 @@ public class WhereCompiler {
  * @throws AmbiguousColumnException if an unaliased column name is 
ambiguous across multiple tables
  */
 public static Expression compile(StatementContext context, 
FilterableStatement statement, ParseNode viewWhere, Set 
subqueryNodes) throws SQLException {
-return compile(context, statement, viewWhere, 
Collections.emptyList(), false, subqueryNodes);
+return compile(context, statement, viewWhere, 
Collections.emptyList(), subqueryNodes);
 }
-
+
 /**
  * Optimize scan ranges by applying dynamically generated filter 
expressions.
  * @param context the shared context during query compilation
@@ -118,7 +118,7 @@ public class WhereCompiler {
  * @throws ColumnNotFoundException if column name could not be resolved
  * @throws AmbiguousColumnException if an unaliased column name is 
ambiguous across multiple tables
  */
-public static Expression compile(StatementCon

phoenix git commit: PHOENIX-4692 ArrayIndexOutOfBoundsException in ScanRanges.intersectScan

2018-05-21 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/5.x-HBase-2.0 87ab023de -> 9b921b294


PHOENIX-4692 ArrayIndexOutOfBoundsException in ScanRanges.intersectScan


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

Branch: refs/heads/5.x-HBase-2.0
Commit: 9b921b2945cdb64822f8d83e7acb52458e762c9d
Parents: 87ab023
Author: maryannxue <maryann@gmail.com>
Authored: Mon May 21 10:07:27 2018 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Mon May 21 10:07:27 2018 -0700

--
 .../apache/phoenix/end2end/SkipScanQueryIT.java | 21 
 .../apache/phoenix/compile/WhereCompiler.java   | 12 +--
 .../apache/phoenix/execute/BaseQueryPlan.java   |  2 +-
 .../apache/phoenix/execute/HashJoinPlan.java|  5 -
 4 files changed, 32 insertions(+), 8 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/9b921b29/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
index c4e4a9e..e823559 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
@@ -564,4 +564,25 @@ public class SkipScanQueryIT extends 
ParallelStatsDisabledIT {
 assertFalse(rs.next());
 }
 }
+
+@Test
+public void testSkipScanJoinOptimization() throws Exception {
+try (Connection conn = DriverManager.getConnection(getUrl())) {
+String tableName = generateUniqueName();
+String viewName = generateUniqueName();
+String idxName = "IDX_" + tableName;
+conn.setAutoCommit(true);
+conn.createStatement().execute(
+"create table " + tableName + " (PK1 INTEGER NOT NULL, PK2 
INTEGER NOT NULL, " +
+" ID1 INTEGER, ID2 INTEGER CONSTRAINT PK PRIMARY 
KEY(PK1 , PK2))SALT_BUCKETS = 4");
+conn.createStatement().execute("upsert into " + tableName + " 
values (1,1,1,1)");
+conn.createStatement().execute("upsert into " + tableName + " 
values (2,2,2,2)");
+conn.createStatement().execute("upsert into " + tableName + " 
values (2,3,1,2)");
+conn.createStatement().execute("create view " + viewName + " as 
select * from " +
+tableName + " where PK1 in (1,2)");
+conn.createStatement().execute("create index " + idxName + " on " 
+ viewName + " (ID1)");
+ResultSet rs = conn.createStatement().executeQuery("select /*+ 
INDEX(" + viewName + " " + idxName + ") */ * from " + viewName + " where ID1 = 
1 ");
+assertTrue(rs.next());
+}
+}
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9b921b29/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
index 2cf5857..832b1f0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
@@ -105,9 +105,9 @@ public class WhereCompiler {
  * @throws AmbiguousColumnException if an unaliased column name is 
ambiguous across multiple tables
  */
 public static Expression compile(StatementContext context, 
FilterableStatement statement, ParseNode viewWhere, Set 
subqueryNodes) throws SQLException {
-return compile(context, statement, viewWhere, 
Collections.emptyList(), false, subqueryNodes);
+return compile(context, statement, viewWhere, 
Collections.emptyList(), subqueryNodes);
 }
-
+
 /**
  * Optimize scan ranges by applying dynamically generated filter 
expressions.
  * @param context the shared context during query compilation
@@ -118,7 +118,7 @@ public class WhereCompiler {
  * @throws ColumnNotFoundException if column name could not be resolved
  * @throws AmbiguousColumnException if an unaliased column name is 
ambiguous across multiple tables
  */
-public static Expression compile(StatementCon

phoenix git commit: PHOENIX-4692 ArrayIndexOutOfBoundsException in ScanRanges.intersectScan

2018-05-18 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/master 58415e2f3 -> 28b9de0da


PHOENIX-4692 ArrayIndexOutOfBoundsException in ScanRanges.intersectScan


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

Branch: refs/heads/master
Commit: 28b9de0da01b61e61c749ed433ddb995596b3e45
Parents: 58415e2
Author: maryannxue <maryann@gmail.com>
Authored: Fri May 18 19:46:29 2018 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Fri May 18 19:46:29 2018 -0700

--
 .../apache/phoenix/end2end/SkipScanQueryIT.java | 21 
 .../apache/phoenix/compile/WhereCompiler.java   | 12 +--
 .../apache/phoenix/execute/BaseQueryPlan.java   |  2 +-
 .../apache/phoenix/execute/HashJoinPlan.java|  5 -
 4 files changed, 32 insertions(+), 8 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/28b9de0d/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
index d98bbe2..fb0b568 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SkipScanQueryIT.java
@@ -563,4 +563,25 @@ public class SkipScanQueryIT extends 
ParallelStatsDisabledIT {
 assertFalse(rs.next());
 }
 }
+
+@Test
+public void testSkipScanJoinOptimization() throws Exception {
+try (Connection conn = DriverManager.getConnection(getUrl())) {
+String tableName = generateUniqueName();
+String viewName = generateUniqueName();
+String idxName = "IDX_" + tableName;
+conn.setAutoCommit(true);
+conn.createStatement().execute(
+"create table " + tableName + " (PK1 INTEGER NOT NULL, PK2 
INTEGER NOT NULL, " +
+" ID1 INTEGER, ID2 INTEGER CONSTRAINT PK PRIMARY 
KEY(PK1 , PK2))SALT_BUCKETS = 4");
+conn.createStatement().execute("upsert into " + tableName + " 
values (1,1,1,1)");
+conn.createStatement().execute("upsert into " + tableName + " 
values (2,2,2,2)");
+conn.createStatement().execute("upsert into " + tableName + " 
values (2,3,1,2)");
+conn.createStatement().execute("create view " + viewName + " as 
select * from " +
+tableName + " where PK1 in (1,2)");
+conn.createStatement().execute("create index " + idxName + " on " 
+ viewName + " (ID1)");
+ResultSet rs = conn.createStatement().executeQuery("select /*+ 
INDEX(" + viewName + " " + idxName + ") */ * from " + viewName + " where ID1 = 
1 ");
+assertTrue(rs.next());
+}
+}
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/28b9de0d/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
index 2cf5857..832b1f0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/WhereCompiler.java
@@ -105,9 +105,9 @@ public class WhereCompiler {
  * @throws AmbiguousColumnException if an unaliased column name is 
ambiguous across multiple tables
  */
 public static Expression compile(StatementContext context, 
FilterableStatement statement, ParseNode viewWhere, Set 
subqueryNodes) throws SQLException {
-return compile(context, statement, viewWhere, 
Collections.emptyList(), false, subqueryNodes);
+return compile(context, statement, viewWhere, 
Collections.emptyList(), subqueryNodes);
 }
-
+
 /**
  * Optimize scan ranges by applying dynamically generated filter 
expressions.
  * @param context the shared context during query compilation
@@ -118,7 +118,7 @@ public class WhereCompiler {
  * @throws ColumnNotFoundException if column name could not be resolved
  * @throws AmbiguousColumnException if an unaliased column name is 
ambiguous across multiple tables
  */
-public static Expression compile(StatementContext con

phoenix git commit: PHOENIX-4616 Move join query optimization out from QueryCompiler into QueryOptimizer (addendum)

2018-04-06 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/5.x-HBase-2.0 fe03c3006 -> 6521c87a0


PHOENIX-4616 Move join query optimization out from QueryCompiler into 
QueryOptimizer (addendum)


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

Branch: refs/heads/5.x-HBase-2.0
Commit: 6521c87a03c001908f0d4fabf0f968e72c2d0a89
Parents: fe03c30
Author: maryannxue <maryann@gmail.com>
Authored: Fri Apr 6 14:04:02 2018 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Fri Apr 6 14:04:02 2018 -0700

--
 .../org/apache/phoenix/optimize/QueryOptimizer.java | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/6521c87a/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java 
b/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
index 44baee4..4f2a5e9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
@@ -38,7 +38,6 @@ import org.apache.phoenix.compile.SequenceManager;
 import org.apache.phoenix.compile.StatementContext;
 import org.apache.phoenix.compile.StatementNormalizer;
 import org.apache.phoenix.compile.SubqueryRewriter;
-import org.apache.phoenix.execute.BaseQueryPlan;
 import org.apache.phoenix.iterate.ParallelIteratorFactory;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixStatement;
@@ -123,11 +122,14 @@ public class QueryOptimizer {
 return Collections.singletonList(dataPlan);
 }
 
-if (dataPlan instanceof BaseQueryPlan) {
-return getApplicablePlans((BaseQueryPlan) dataPlan, statement, 
targetColumns, parallelIteratorFactory, stopAtBestPlan);
+SelectStatement select = (SelectStatement) dataPlan.getStatement();
+if (!select.isUnion()
+&& !select.isJoin()
+&& select.getInnerSelectStatement() == null
+&& (select.getWhere() == null || 
!select.getWhere().hasSubquery())) {
+return getApplicablePlansForSingleFlatQuery(dataPlan, statement, 
targetColumns, parallelIteratorFactory, stopAtBestPlan);
 }
 
-SelectStatement select = (SelectStatement) dataPlan.getStatement();
 ColumnResolver resolver = FromCompiler.getResolverForQuery(select, 
statement.getConnection());
 Map<TableRef, QueryPlan> dataPlans = null;
 
@@ -184,7 +186,7 @@ public class QueryOptimizer {
 return Collections.singletonList(compiler.compile());
 }
 
-private List getApplicablePlans(BaseQueryPlan dataPlan, 
PhoenixStatement statement, List targetColumns, 
ParallelIteratorFactory parallelIteratorFactory, boolean stopAtBestPlan) throws 
SQLException {
+private List getApplicablePlansForSingleFlatQuery(QueryPlan 
dataPlan, PhoenixStatement statement, List targetColumns, 
ParallelIteratorFactory parallelIteratorFactory, boolean stopAtBestPlan) throws 
SQLException {
 SelectStatement select = (SelectStatement)dataPlan.getStatement();
 // Exit early if we have a point lookup as we can't get better than 
that
 if (dataPlan.getContext().getScanRanges().isPointLookup() && 
stopAtBestPlan) {



phoenix git commit: PHOENIX-4616 Move join query optimization out from QueryCompiler into QueryOptimizer (addendum)

2018-04-06 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 268e744d6 -> b52f467d9


PHOENIX-4616 Move join query optimization out from QueryCompiler into 
QueryOptimizer (addendum)


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

Branch: refs/heads/4.x-HBase-0.98
Commit: b52f467d970b2682b7a70952956144c965c472ba
Parents: 268e744
Author: maryannxue <maryann@gmail.com>
Authored: Fri Apr 6 13:58:47 2018 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Fri Apr 6 13:58:47 2018 -0700

--
 .../org/apache/phoenix/optimize/QueryOptimizer.java | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/b52f467d/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java 
b/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
index 31f5c34..6d668cc 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
@@ -38,7 +38,6 @@ import org.apache.phoenix.compile.SequenceManager;
 import org.apache.phoenix.compile.StatementContext;
 import org.apache.phoenix.compile.StatementNormalizer;
 import org.apache.phoenix.compile.SubqueryRewriter;
-import org.apache.phoenix.execute.BaseQueryPlan;
 import org.apache.phoenix.iterate.ParallelIteratorFactory;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixStatement;
@@ -126,11 +125,14 @@ public class QueryOptimizer {
 return Collections.singletonList(dataPlan);
 }
 
-if (dataPlan instanceof BaseQueryPlan) {
-return getApplicablePlans((BaseQueryPlan) dataPlan, statement, 
targetColumns, parallelIteratorFactory, stopAtBestPlan);
+SelectStatement select = (SelectStatement) dataPlan.getStatement();
+if (!select.isUnion()
+&& !select.isJoin()
+&& select.getInnerSelectStatement() == null
+&& (select.getWhere() == null || 
!select.getWhere().hasSubquery())) {
+return getApplicablePlansForSingleFlatQuery(dataPlan, statement, 
targetColumns, parallelIteratorFactory, stopAtBestPlan);
 }
 
-SelectStatement select = (SelectStatement) dataPlan.getStatement();
 ColumnResolver resolver = FromCompiler.getResolverForQuery(select, 
statement.getConnection());
 Map<TableRef, QueryPlan> dataPlans = null;
 
@@ -187,7 +189,7 @@ public class QueryOptimizer {
 return Collections.singletonList(compiler.compile());
 }
 
-private List getApplicablePlans(BaseQueryPlan dataPlan, 
PhoenixStatement statement, List targetColumns, 
ParallelIteratorFactory parallelIteratorFactory, boolean stopAtBestPlan) throws 
SQLException {
+private List getApplicablePlansForSingleFlatQuery(QueryPlan 
dataPlan, PhoenixStatement statement, List targetColumns, 
ParallelIteratorFactory parallelIteratorFactory, boolean stopAtBestPlan) throws 
SQLException {
 SelectStatement select = (SelectStatement)dataPlan.getStatement();
 // Exit early if we have a point lookup as we can't get better than 
that
 if (dataPlan.getContext().getScanRanges().isPointLookup() && 
stopAtBestPlan) {



phoenix git commit: PHOENIX-4616 Move join query optimization out from QueryCompiler into QueryOptimizer (addendum)

2018-04-06 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.1 d147d8f06 -> 1b7f58104


PHOENIX-4616 Move join query optimization out from QueryCompiler into 
QueryOptimizer (addendum)


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

Branch: refs/heads/4.x-HBase-1.1
Commit: 1b7f58104b033e613e1ca939aa53ae11f6b43385
Parents: d147d8f
Author: maryannxue <maryann@gmail.com>
Authored: Fri Apr 6 13:58:15 2018 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Fri Apr 6 13:58:15 2018 -0700

--
 .../org/apache/phoenix/optimize/QueryOptimizer.java | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/1b7f5810/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java 
b/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
index 31f5c34..6d668cc 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
@@ -38,7 +38,6 @@ import org.apache.phoenix.compile.SequenceManager;
 import org.apache.phoenix.compile.StatementContext;
 import org.apache.phoenix.compile.StatementNormalizer;
 import org.apache.phoenix.compile.SubqueryRewriter;
-import org.apache.phoenix.execute.BaseQueryPlan;
 import org.apache.phoenix.iterate.ParallelIteratorFactory;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixStatement;
@@ -126,11 +125,14 @@ public class QueryOptimizer {
 return Collections.singletonList(dataPlan);
 }
 
-if (dataPlan instanceof BaseQueryPlan) {
-return getApplicablePlans((BaseQueryPlan) dataPlan, statement, 
targetColumns, parallelIteratorFactory, stopAtBestPlan);
+SelectStatement select = (SelectStatement) dataPlan.getStatement();
+if (!select.isUnion()
+&& !select.isJoin()
+&& select.getInnerSelectStatement() == null
+&& (select.getWhere() == null || 
!select.getWhere().hasSubquery())) {
+return getApplicablePlansForSingleFlatQuery(dataPlan, statement, 
targetColumns, parallelIteratorFactory, stopAtBestPlan);
 }
 
-SelectStatement select = (SelectStatement) dataPlan.getStatement();
 ColumnResolver resolver = FromCompiler.getResolverForQuery(select, 
statement.getConnection());
 Map<TableRef, QueryPlan> dataPlans = null;
 
@@ -187,7 +189,7 @@ public class QueryOptimizer {
 return Collections.singletonList(compiler.compile());
 }
 
-private List getApplicablePlans(BaseQueryPlan dataPlan, 
PhoenixStatement statement, List targetColumns, 
ParallelIteratorFactory parallelIteratorFactory, boolean stopAtBestPlan) throws 
SQLException {
+private List getApplicablePlansForSingleFlatQuery(QueryPlan 
dataPlan, PhoenixStatement statement, List targetColumns, 
ParallelIteratorFactory parallelIteratorFactory, boolean stopAtBestPlan) throws 
SQLException {
 SelectStatement select = (SelectStatement)dataPlan.getStatement();
 // Exit early if we have a point lookup as we can't get better than 
that
 if (dataPlan.getContext().getScanRanges().isPointLookup() && 
stopAtBestPlan) {



phoenix git commit: PHOENIX-4616 Move join query optimization out from QueryCompiler into QueryOptimizer (addendum)

2018-04-06 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.3 995f417da -> fb9626117


PHOENIX-4616 Move join query optimization out from QueryCompiler into 
QueryOptimizer (addendum)


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

Branch: refs/heads/4.x-HBase-1.3
Commit: fb9626117ec5d4c498c989f38fa077ab4acaef18
Parents: 995f417
Author: maryannxue <maryann@gmail.com>
Authored: Fri Apr 6 13:57:32 2018 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Fri Apr 6 13:57:32 2018 -0700

--
 .../org/apache/phoenix/optimize/QueryOptimizer.java | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/fb962611/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java 
b/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
index 31f5c34..6d668cc 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
@@ -38,7 +38,6 @@ import org.apache.phoenix.compile.SequenceManager;
 import org.apache.phoenix.compile.StatementContext;
 import org.apache.phoenix.compile.StatementNormalizer;
 import org.apache.phoenix.compile.SubqueryRewriter;
-import org.apache.phoenix.execute.BaseQueryPlan;
 import org.apache.phoenix.iterate.ParallelIteratorFactory;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixStatement;
@@ -126,11 +125,14 @@ public class QueryOptimizer {
 return Collections.singletonList(dataPlan);
 }
 
-if (dataPlan instanceof BaseQueryPlan) {
-return getApplicablePlans((BaseQueryPlan) dataPlan, statement, 
targetColumns, parallelIteratorFactory, stopAtBestPlan);
+SelectStatement select = (SelectStatement) dataPlan.getStatement();
+if (!select.isUnion()
+&& !select.isJoin()
+&& select.getInnerSelectStatement() == null
+&& (select.getWhere() == null || 
!select.getWhere().hasSubquery())) {
+return getApplicablePlansForSingleFlatQuery(dataPlan, statement, 
targetColumns, parallelIteratorFactory, stopAtBestPlan);
 }
 
-SelectStatement select = (SelectStatement) dataPlan.getStatement();
 ColumnResolver resolver = FromCompiler.getResolverForQuery(select, 
statement.getConnection());
 Map<TableRef, QueryPlan> dataPlans = null;
 
@@ -187,7 +189,7 @@ public class QueryOptimizer {
 return Collections.singletonList(compiler.compile());
 }
 
-private List getApplicablePlans(BaseQueryPlan dataPlan, 
PhoenixStatement statement, List targetColumns, 
ParallelIteratorFactory parallelIteratorFactory, boolean stopAtBestPlan) throws 
SQLException {
+private List getApplicablePlansForSingleFlatQuery(QueryPlan 
dataPlan, PhoenixStatement statement, List targetColumns, 
ParallelIteratorFactory parallelIteratorFactory, boolean stopAtBestPlan) throws 
SQLException {
 SelectStatement select = (SelectStatement)dataPlan.getStatement();
 // Exit early if we have a point lookup as we can't get better than 
that
 if (dataPlan.getContext().getScanRanges().isPointLookup() && 
stopAtBestPlan) {



phoenix git commit: PHOENIX-4616 Move join query optimization out from QueryCompiler into QueryOptimizer (addendum)

2018-04-06 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.2 8b2ebe003 -> 52d3c7d01


PHOENIX-4616 Move join query optimization out from QueryCompiler into 
QueryOptimizer (addendum)


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

Branch: refs/heads/4.x-HBase-1.2
Commit: 52d3c7d015c0f929e97e1a50ab815d9570fcf248
Parents: 8b2ebe0
Author: maryannxue <maryann@gmail.com>
Authored: Fri Apr 6 10:05:52 2018 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Fri Apr 6 10:05:52 2018 -0700

--
 .../org/apache/phoenix/optimize/QueryOptimizer.java | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/52d3c7d0/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java 
b/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
index 31f5c34..6d668cc 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
@@ -38,7 +38,6 @@ import org.apache.phoenix.compile.SequenceManager;
 import org.apache.phoenix.compile.StatementContext;
 import org.apache.phoenix.compile.StatementNormalizer;
 import org.apache.phoenix.compile.SubqueryRewriter;
-import org.apache.phoenix.execute.BaseQueryPlan;
 import org.apache.phoenix.iterate.ParallelIteratorFactory;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixStatement;
@@ -126,11 +125,14 @@ public class QueryOptimizer {
 return Collections.singletonList(dataPlan);
 }
 
-if (dataPlan instanceof BaseQueryPlan) {
-return getApplicablePlans((BaseQueryPlan) dataPlan, statement, 
targetColumns, parallelIteratorFactory, stopAtBestPlan);
+SelectStatement select = (SelectStatement) dataPlan.getStatement();
+if (!select.isUnion()
+&& !select.isJoin()
+&& select.getInnerSelectStatement() == null
+&& (select.getWhere() == null || 
!select.getWhere().hasSubquery())) {
+return getApplicablePlansForSingleFlatQuery(dataPlan, statement, 
targetColumns, parallelIteratorFactory, stopAtBestPlan);
 }
 
-SelectStatement select = (SelectStatement) dataPlan.getStatement();
 ColumnResolver resolver = FromCompiler.getResolverForQuery(select, 
statement.getConnection());
 Map<TableRef, QueryPlan> dataPlans = null;
 
@@ -187,7 +189,7 @@ public class QueryOptimizer {
 return Collections.singletonList(compiler.compile());
 }
 
-private List getApplicablePlans(BaseQueryPlan dataPlan, 
PhoenixStatement statement, List targetColumns, 
ParallelIteratorFactory parallelIteratorFactory, boolean stopAtBestPlan) throws 
SQLException {
+private List getApplicablePlansForSingleFlatQuery(QueryPlan 
dataPlan, PhoenixStatement statement, List targetColumns, 
ParallelIteratorFactory parallelIteratorFactory, boolean stopAtBestPlan) throws 
SQLException {
 SelectStatement select = (SelectStatement)dataPlan.getStatement();
 // Exit early if we have a point lookup as we can't get better than 
that
 if (dataPlan.getContext().getScanRanges().isPointLookup() && 
stopAtBestPlan) {



phoenix git commit: PHOENIX-4616 Move join query optimization out from QueryCompiler into QueryOptimizer (addendum)

2018-04-05 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/master 49fca494b -> 0b1b219ef


PHOENIX-4616 Move join query optimization out from QueryCompiler into 
QueryOptimizer (addendum)


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

Branch: refs/heads/master
Commit: 0b1b219ef0e803d7ff254408c24b4bb67a5d88f9
Parents: 49fca49
Author: maryannxue <maryann@gmail.com>
Authored: Thu Apr 5 19:33:53 2018 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Thu Apr 5 19:33:53 2018 -0700

--
 .../main/java/org/apache/phoenix/optimize/QueryOptimizer.java   | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/0b1b219e/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java 
b/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
index 3a2d11e..6d668cc 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
@@ -126,7 +126,10 @@ public class QueryOptimizer {
 }
 
 SelectStatement select = (SelectStatement) dataPlan.getStatement();
-if (!select.isUnion() && !select.isJoin() && 
select.getInnerSelectStatement() == null) {
+if (!select.isUnion()
+&& !select.isJoin()
+&& select.getInnerSelectStatement() == null
+&& (select.getWhere() == null || 
!select.getWhere().hasSubquery())) {
 return getApplicablePlansForSingleFlatQuery(dataPlan, statement, 
targetColumns, parallelIteratorFactory, stopAtBestPlan);
 }
 



phoenix git commit: PHOENIX-4616 Move join query optimization out from QueryCompiler into QueryOptimizer (addendum)

2018-04-05 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/master 701c447d3 -> 49fca494b


PHOENIX-4616 Move join query optimization out from QueryCompiler into 
QueryOptimizer (addendum)


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

Branch: refs/heads/master
Commit: 49fca494bf9e13918db558e8276676e3dfda9d74
Parents: 701c447
Author: maryannxue <maryann@gmail.com>
Authored: Thu Apr 5 17:38:30 2018 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Thu Apr 5 17:38:30 2018 -0700

--
 .../java/org/apache/phoenix/optimize/QueryOptimizer.java| 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/49fca494/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java 
b/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
index 31f5c34..3a2d11e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/optimize/QueryOptimizer.java
@@ -38,7 +38,6 @@ import org.apache.phoenix.compile.SequenceManager;
 import org.apache.phoenix.compile.StatementContext;
 import org.apache.phoenix.compile.StatementNormalizer;
 import org.apache.phoenix.compile.SubqueryRewriter;
-import org.apache.phoenix.execute.BaseQueryPlan;
 import org.apache.phoenix.iterate.ParallelIteratorFactory;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixStatement;
@@ -126,11 +125,11 @@ public class QueryOptimizer {
 return Collections.singletonList(dataPlan);
 }
 
-if (dataPlan instanceof BaseQueryPlan) {
-return getApplicablePlans((BaseQueryPlan) dataPlan, statement, 
targetColumns, parallelIteratorFactory, stopAtBestPlan);
+SelectStatement select = (SelectStatement) dataPlan.getStatement();
+if (!select.isUnion() && !select.isJoin() && 
select.getInnerSelectStatement() == null) {
+return getApplicablePlansForSingleFlatQuery(dataPlan, statement, 
targetColumns, parallelIteratorFactory, stopAtBestPlan);
 }
 
-SelectStatement select = (SelectStatement) dataPlan.getStatement();
 ColumnResolver resolver = FromCompiler.getResolverForQuery(select, 
statement.getConnection());
 Map<TableRef, QueryPlan> dataPlans = null;
 
@@ -187,7 +186,7 @@ public class QueryOptimizer {
 return Collections.singletonList(compiler.compile());
 }
 
-private List getApplicablePlans(BaseQueryPlan dataPlan, 
PhoenixStatement statement, List targetColumns, 
ParallelIteratorFactory parallelIteratorFactory, boolean stopAtBestPlan) throws 
SQLException {
+private List getApplicablePlansForSingleFlatQuery(QueryPlan 
dataPlan, PhoenixStatement statement, List targetColumns, 
ParallelIteratorFactory parallelIteratorFactory, boolean stopAtBestPlan) throws 
SQLException {
 SelectStatement select = (SelectStatement)dataPlan.getStatement();
 // Exit early if we have a point lookup as we can't get better than 
that
 if (dataPlan.getContext().getScanRanges().isPointLookup() && 
stopAtBestPlan) {



phoenix git commit: PHOENIX-4616 Move join query optimization out from QueryCompiler into QueryOptimizer

2018-04-03 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/5.x-HBase-2.0 bdca54a69 -> 3c1b3b547


PHOENIX-4616 Move join query optimization out from QueryCompiler into 
QueryOptimizer


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

Branch: refs/heads/5.x-HBase-2.0
Commit: 3c1b3b547f88cc2860b16658a0babe3e05d34c8e
Parents: bdca54a
Author: maryannxue <maryann@gmail.com>
Authored: Tue Apr 3 20:01:59 2018 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Tue Apr 3 20:01:59 2018 -0700

--
 .../apache/phoenix/end2end/join/BaseJoinIT.java |   2 +
 .../apache/phoenix/compile/JoinCompiler.java| 298 ++-
 .../apache/phoenix/compile/QueryCompiler.java   |  79 +++--
 .../phoenix/compile/SubselectRewriter.java  |   5 +
 .../apache/phoenix/compile/UpsertCompiler.java  |   2 +-
 .../apache/phoenix/jdbc/PhoenixStatement.java   |   2 +-
 .../GenSubqueryParamValuesRewriter.java | 153 ++
 .../apache/phoenix/optimize/QueryOptimizer.java | 175 ++-
 .../phoenix/compile/QueryCompilerTest.java  | 114 ++-
 9 files changed, 564 insertions(+), 266 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/3c1b3b54/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java
index 6e03a37..4d4660c 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java
@@ -34,6 +34,7 @@ import java.util.regex.Pattern;
 
 import org.apache.phoenix.cache.ServerCacheClient;
 import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
+import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.SchemaUtil;
 import org.apache.phoenix.util.StringUtil;
@@ -456,6 +457,7 @@ public abstract class BaseJoinIT extends 
ParallelStatsDisabledIT {
protected Connection getConnection() throws SQLException {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);

props.put(ServerCacheClient.HASH_JOIN_SERVER_CACHE_RESEND_PER_SERVER, "true");
+props.put(QueryServices.FORCE_ROW_KEY_ORDER_ATTRIB, "true");
return DriverManager.getConnection(getUrl(), props);
}


http://git-wip-us.apache.org/repos/asf/phoenix/blob/3c1b3b54/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
index cf5a5dc..88e8f50 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
@@ -40,7 +40,7 @@ import org.apache.phoenix.expression.AndExpression;
 import org.apache.phoenix.expression.CoerceExpression;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.LiteralExpression;
-import org.apache.phoenix.expression.function.CountAggregateFunction;
+import org.apache.phoenix.expression.function.MinAggregateFunction;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixStatement;
 import org.apache.phoenix.parse.AliasedNode;
@@ -53,26 +53,19 @@ import org.apache.phoenix.parse.ComparisonParseNode;
 import org.apache.phoenix.parse.ConcreteTableNode;
 import org.apache.phoenix.parse.DerivedTableNode;
 import org.apache.phoenix.parse.EqualParseNode;
-import org.apache.phoenix.parse.HintNode;
 import org.apache.phoenix.parse.HintNode.Hint;
-import org.apache.phoenix.parse.IndexExpressionParseNodeRewriter;
 import org.apache.phoenix.parse.JoinTableNode;
 import org.apache.phoenix.parse.JoinTableNode.JoinType;
 import org.apache.phoenix.parse.NamedTableNode;
 import org.apache.phoenix.parse.OrderByNode;
 import org.apache.phoenix.parse.ParseNode;
 import org.apache.phoenix.parse.ParseNodeFactory;
-import org.apache.phoenix.parse.ParseNodeRewriter;
 import org.apache.phoenix.parse.SelectStatement;
 import org.apache.phoenix.parse.StatelessTraverseAllParseNodeVisitor;
 import org.apache.phoenix.parse.TableName;
 import org.apache.phoenix.parse.TableNode;
 import org.apache.phoenix.parse.TableNodeVisitor;
 import org.apache.phoenix.pa

phoenix git commit: PHOENIX-4616 Move join query optimization out from QueryCompiler into QueryOptimizer

2018-04-03 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.1 b97378aff -> f5376c418


PHOENIX-4616 Move join query optimization out from QueryCompiler into 
QueryOptimizer


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

Branch: refs/heads/4.x-HBase-1.1
Commit: f5376c418eed3d1b24c25a6c6e6ff1e87e8ee766
Parents: b97378a
Author: maryannxue <maryann@gmail.com>
Authored: Tue Apr 3 17:21:32 2018 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Tue Apr 3 17:21:32 2018 -0700

--
 .../apache/phoenix/end2end/join/BaseJoinIT.java |   2 +
 .../apache/phoenix/compile/JoinCompiler.java| 298 ++-
 .../apache/phoenix/compile/QueryCompiler.java   |  79 +++--
 .../phoenix/compile/SubselectRewriter.java  |   5 +
 .../apache/phoenix/compile/UpsertCompiler.java  |   2 +-
 .../apache/phoenix/jdbc/PhoenixStatement.java   |   2 +-
 .../GenSubqueryParamValuesRewriter.java | 153 ++
 .../apache/phoenix/optimize/QueryOptimizer.java | 172 ++-
 .../phoenix/compile/QueryCompilerTest.java  | 114 ++-
 9 files changed, 561 insertions(+), 266 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/f5376c41/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java
index 6e03a37..4d4660c 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java
@@ -34,6 +34,7 @@ import java.util.regex.Pattern;
 
 import org.apache.phoenix.cache.ServerCacheClient;
 import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
+import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.SchemaUtil;
 import org.apache.phoenix.util.StringUtil;
@@ -456,6 +457,7 @@ public abstract class BaseJoinIT extends 
ParallelStatsDisabledIT {
protected Connection getConnection() throws SQLException {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);

props.put(ServerCacheClient.HASH_JOIN_SERVER_CACHE_RESEND_PER_SERVER, "true");
+props.put(QueryServices.FORCE_ROW_KEY_ORDER_ATTRIB, "true");
return DriverManager.getConnection(getUrl(), props);
}


http://git-wip-us.apache.org/repos/asf/phoenix/blob/f5376c41/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
index cf5a5dc..88e8f50 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
@@ -40,7 +40,7 @@ import org.apache.phoenix.expression.AndExpression;
 import org.apache.phoenix.expression.CoerceExpression;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.LiteralExpression;
-import org.apache.phoenix.expression.function.CountAggregateFunction;
+import org.apache.phoenix.expression.function.MinAggregateFunction;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixStatement;
 import org.apache.phoenix.parse.AliasedNode;
@@ -53,26 +53,19 @@ import org.apache.phoenix.parse.ComparisonParseNode;
 import org.apache.phoenix.parse.ConcreteTableNode;
 import org.apache.phoenix.parse.DerivedTableNode;
 import org.apache.phoenix.parse.EqualParseNode;
-import org.apache.phoenix.parse.HintNode;
 import org.apache.phoenix.parse.HintNode.Hint;
-import org.apache.phoenix.parse.IndexExpressionParseNodeRewriter;
 import org.apache.phoenix.parse.JoinTableNode;
 import org.apache.phoenix.parse.JoinTableNode.JoinType;
 import org.apache.phoenix.parse.NamedTableNode;
 import org.apache.phoenix.parse.OrderByNode;
 import org.apache.phoenix.parse.ParseNode;
 import org.apache.phoenix.parse.ParseNodeFactory;
-import org.apache.phoenix.parse.ParseNodeRewriter;
 import org.apache.phoenix.parse.SelectStatement;
 import org.apache.phoenix.parse.StatelessTraverseAllParseNodeVisitor;
 import org.apache.phoenix.parse.TableName;
 import org.apache.phoenix.parse.TableNode;
 import org.apache.phoenix.parse.TableNodeVisitor;
 import org.apache.phoenix.pa

phoenix git commit: PHOENIX-4616 Move join query optimization out from QueryCompiler into QueryOptimizer

2018-04-03 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.2 d1668b9cc -> 82414d7d3


PHOENIX-4616 Move join query optimization out from QueryCompiler into 
QueryOptimizer


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

Branch: refs/heads/4.x-HBase-1.2
Commit: 82414d7d3146cbf2073f39343e3c064b2b729209
Parents: d1668b9
Author: maryannxue <maryann@gmail.com>
Authored: Tue Apr 3 17:16:10 2018 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Tue Apr 3 17:16:10 2018 -0700

--
 .../apache/phoenix/end2end/join/BaseJoinIT.java |   2 +
 .../apache/phoenix/compile/JoinCompiler.java| 298 ++-
 .../apache/phoenix/compile/QueryCompiler.java   |  79 +++--
 .../phoenix/compile/SubselectRewriter.java  |   5 +
 .../apache/phoenix/compile/UpsertCompiler.java  |   2 +-
 .../apache/phoenix/jdbc/PhoenixStatement.java   |   2 +-
 .../GenSubqueryParamValuesRewriter.java | 153 ++
 .../apache/phoenix/optimize/QueryOptimizer.java | 172 ++-
 .../phoenix/compile/QueryCompilerTest.java  | 114 ++-
 9 files changed, 561 insertions(+), 266 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/82414d7d/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java
index 6e03a37..4d4660c 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java
@@ -34,6 +34,7 @@ import java.util.regex.Pattern;
 
 import org.apache.phoenix.cache.ServerCacheClient;
 import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
+import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.SchemaUtil;
 import org.apache.phoenix.util.StringUtil;
@@ -456,6 +457,7 @@ public abstract class BaseJoinIT extends 
ParallelStatsDisabledIT {
protected Connection getConnection() throws SQLException {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);

props.put(ServerCacheClient.HASH_JOIN_SERVER_CACHE_RESEND_PER_SERVER, "true");
+props.put(QueryServices.FORCE_ROW_KEY_ORDER_ATTRIB, "true");
return DriverManager.getConnection(getUrl(), props);
}


http://git-wip-us.apache.org/repos/asf/phoenix/blob/82414d7d/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
index cf5a5dc..88e8f50 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
@@ -40,7 +40,7 @@ import org.apache.phoenix.expression.AndExpression;
 import org.apache.phoenix.expression.CoerceExpression;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.LiteralExpression;
-import org.apache.phoenix.expression.function.CountAggregateFunction;
+import org.apache.phoenix.expression.function.MinAggregateFunction;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixStatement;
 import org.apache.phoenix.parse.AliasedNode;
@@ -53,26 +53,19 @@ import org.apache.phoenix.parse.ComparisonParseNode;
 import org.apache.phoenix.parse.ConcreteTableNode;
 import org.apache.phoenix.parse.DerivedTableNode;
 import org.apache.phoenix.parse.EqualParseNode;
-import org.apache.phoenix.parse.HintNode;
 import org.apache.phoenix.parse.HintNode.Hint;
-import org.apache.phoenix.parse.IndexExpressionParseNodeRewriter;
 import org.apache.phoenix.parse.JoinTableNode;
 import org.apache.phoenix.parse.JoinTableNode.JoinType;
 import org.apache.phoenix.parse.NamedTableNode;
 import org.apache.phoenix.parse.OrderByNode;
 import org.apache.phoenix.parse.ParseNode;
 import org.apache.phoenix.parse.ParseNodeFactory;
-import org.apache.phoenix.parse.ParseNodeRewriter;
 import org.apache.phoenix.parse.SelectStatement;
 import org.apache.phoenix.parse.StatelessTraverseAllParseNodeVisitor;
 import org.apache.phoenix.parse.TableName;
 import org.apache.phoenix.parse.TableNode;
 import org.apache.phoenix.parse.TableNodeVisitor;
 import org.apache.phoenix.pa

phoenix git commit: PHOENIX-4616 Move join query optimization out from QueryCompiler into QueryOptimizer

2018-04-03 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.3 037b7cbe3 -> 781a9c09c


PHOENIX-4616 Move join query optimization out from QueryCompiler into 
QueryOptimizer


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

Branch: refs/heads/4.x-HBase-1.3
Commit: 781a9c09c31d1e3090886b77d18638dfee7b615d
Parents: 037b7cb
Author: maryannxue <maryann@gmail.com>
Authored: Tue Apr 3 17:13:39 2018 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Tue Apr 3 17:13:39 2018 -0700

--
 .../apache/phoenix/end2end/join/BaseJoinIT.java |   2 +
 .../apache/phoenix/compile/JoinCompiler.java| 298 ++-
 .../apache/phoenix/compile/QueryCompiler.java   |  79 +++--
 .../phoenix/compile/SubselectRewriter.java  |   5 +
 .../apache/phoenix/compile/UpsertCompiler.java  |   2 +-
 .../apache/phoenix/jdbc/PhoenixStatement.java   |   2 +-
 .../GenSubqueryParamValuesRewriter.java | 153 ++
 .../apache/phoenix/optimize/QueryOptimizer.java | 172 ++-
 .../phoenix/compile/QueryCompilerTest.java  | 114 ++-
 9 files changed, 561 insertions(+), 266 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/781a9c09/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java
index 6e03a37..4d4660c 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java
@@ -34,6 +34,7 @@ import java.util.regex.Pattern;
 
 import org.apache.phoenix.cache.ServerCacheClient;
 import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
+import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.SchemaUtil;
 import org.apache.phoenix.util.StringUtil;
@@ -456,6 +457,7 @@ public abstract class BaseJoinIT extends 
ParallelStatsDisabledIT {
protected Connection getConnection() throws SQLException {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);

props.put(ServerCacheClient.HASH_JOIN_SERVER_CACHE_RESEND_PER_SERVER, "true");
+props.put(QueryServices.FORCE_ROW_KEY_ORDER_ATTRIB, "true");
return DriverManager.getConnection(getUrl(), props);
}


http://git-wip-us.apache.org/repos/asf/phoenix/blob/781a9c09/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
index cf5a5dc..88e8f50 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
@@ -40,7 +40,7 @@ import org.apache.phoenix.expression.AndExpression;
 import org.apache.phoenix.expression.CoerceExpression;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.LiteralExpression;
-import org.apache.phoenix.expression.function.CountAggregateFunction;
+import org.apache.phoenix.expression.function.MinAggregateFunction;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixStatement;
 import org.apache.phoenix.parse.AliasedNode;
@@ -53,26 +53,19 @@ import org.apache.phoenix.parse.ComparisonParseNode;
 import org.apache.phoenix.parse.ConcreteTableNode;
 import org.apache.phoenix.parse.DerivedTableNode;
 import org.apache.phoenix.parse.EqualParseNode;
-import org.apache.phoenix.parse.HintNode;
 import org.apache.phoenix.parse.HintNode.Hint;
-import org.apache.phoenix.parse.IndexExpressionParseNodeRewriter;
 import org.apache.phoenix.parse.JoinTableNode;
 import org.apache.phoenix.parse.JoinTableNode.JoinType;
 import org.apache.phoenix.parse.NamedTableNode;
 import org.apache.phoenix.parse.OrderByNode;
 import org.apache.phoenix.parse.ParseNode;
 import org.apache.phoenix.parse.ParseNodeFactory;
-import org.apache.phoenix.parse.ParseNodeRewriter;
 import org.apache.phoenix.parse.SelectStatement;
 import org.apache.phoenix.parse.StatelessTraverseAllParseNodeVisitor;
 import org.apache.phoenix.parse.TableName;
 import org.apache.phoenix.parse.TableNode;
 import org.apache.phoenix.parse.TableNodeVisitor;
 import org.apache.phoenix.pa

phoenix git commit: PHOENIX-4616 Move join query optimization out from QueryCompiler into QueryOptimizer

2018-04-03 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/master ec9267721 -> ab16e2a27


PHOENIX-4616 Move join query optimization out from QueryCompiler into 
QueryOptimizer


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

Branch: refs/heads/master
Commit: ab16e2a27eaac70a1e1142d47307559fbde4bd49
Parents: ec92677
Author: maryannxue <maryann@gmail.com>
Authored: Tue Apr 3 13:37:48 2018 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Tue Apr 3 13:37:48 2018 -0700

--
 .../apache/phoenix/end2end/join/BaseJoinIT.java |   2 +
 .../apache/phoenix/compile/JoinCompiler.java| 298 ++-
 .../apache/phoenix/compile/QueryCompiler.java   |  79 +++--
 .../phoenix/compile/SubselectRewriter.java  |   5 +
 .../apache/phoenix/compile/UpsertCompiler.java  |   2 +-
 .../apache/phoenix/jdbc/PhoenixStatement.java   |   2 +-
 .../GenSubqueryParamValuesRewriter.java | 153 ++
 .../apache/phoenix/optimize/QueryOptimizer.java | 172 ++-
 .../phoenix/compile/QueryCompilerTest.java  | 114 ++-
 9 files changed, 561 insertions(+), 266 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/ab16e2a2/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java
index 6e03a37..4d4660c 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/BaseJoinIT.java
@@ -34,6 +34,7 @@ import java.util.regex.Pattern;
 
 import org.apache.phoenix.cache.ServerCacheClient;
 import org.apache.phoenix.end2end.ParallelStatsDisabledIT;
+import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.SchemaUtil;
 import org.apache.phoenix.util.StringUtil;
@@ -456,6 +457,7 @@ public abstract class BaseJoinIT extends 
ParallelStatsDisabledIT {
protected Connection getConnection() throws SQLException {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);

props.put(ServerCacheClient.HASH_JOIN_SERVER_CACHE_RESEND_PER_SERVER, "true");
+props.put(QueryServices.FORCE_ROW_KEY_ORDER_ATTRIB, "true");
return DriverManager.getConnection(getUrl(), props);
}


http://git-wip-us.apache.org/repos/asf/phoenix/blob/ab16e2a2/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
index cf5a5dc..88e8f50 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
@@ -40,7 +40,7 @@ import org.apache.phoenix.expression.AndExpression;
 import org.apache.phoenix.expression.CoerceExpression;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.LiteralExpression;
-import org.apache.phoenix.expression.function.CountAggregateFunction;
+import org.apache.phoenix.expression.function.MinAggregateFunction;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixStatement;
 import org.apache.phoenix.parse.AliasedNode;
@@ -53,26 +53,19 @@ import org.apache.phoenix.parse.ComparisonParseNode;
 import org.apache.phoenix.parse.ConcreteTableNode;
 import org.apache.phoenix.parse.DerivedTableNode;
 import org.apache.phoenix.parse.EqualParseNode;
-import org.apache.phoenix.parse.HintNode;
 import org.apache.phoenix.parse.HintNode.Hint;
-import org.apache.phoenix.parse.IndexExpressionParseNodeRewriter;
 import org.apache.phoenix.parse.JoinTableNode;
 import org.apache.phoenix.parse.JoinTableNode.JoinType;
 import org.apache.phoenix.parse.NamedTableNode;
 import org.apache.phoenix.parse.OrderByNode;
 import org.apache.phoenix.parse.ParseNode;
 import org.apache.phoenix.parse.ParseNodeFactory;
-import org.apache.phoenix.parse.ParseNodeRewriter;
 import org.apache.phoenix.parse.SelectStatement;
 import org.apache.phoenix.parse.StatelessTraverseAllParseNodeVisitor;
 import org.apache.phoenix.parse.TableName;
 import org.apache.phoenix.parse.TableNode;
 import org.apache.phoenix.parse.TableNodeVisitor;
 import org.apache.phoenix.pa

phoenix git commit: PHOENIX-4322 DESC primary key column with variable length does not work in SkipScanFilter

2018-03-14 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.1 10bdafb64 -> 0d01a3cdd


PHOENIX-4322 DESC primary key column with variable length does not work in 
SkipScanFilter


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

Branch: refs/heads/4.x-HBase-1.1
Commit: 0d01a3cdd1c544cf1ef43362aed65b5398f80b5f
Parents: 10bdafb
Author: maryannxue <maryann@gmail.com>
Authored: Tue Dec 5 10:59:41 2017 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Wed Mar 14 22:01:00 2018 -0700

--
 .../it/java/org/apache/phoenix/end2end/SortOrderIT.java  | 11 ++-
 .../expression/RowValueConstructorExpression.java|  4 ++--
 2 files changed, 12 insertions(+), 3 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/0d01a3cd/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
index 655dbb1..3f749c1 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
@@ -167,7 +167,16 @@ public class SortOrderIT extends ParallelStatsDisabledIT {
 runQueryTest(ddl, upsert("oid", "code"), insertedRows, new 
Object[][]{{"o2", 2}}, new WhereCondition("oid", "IN", "('o2')"),
 table);
 }
-
+
+@Test
+public void inDescCompositePK3() throws Exception {
+String table = generateUniqueName();
+String ddl = "CREATE table " + table + " (oid VARCHAR NOT NULL, code 
VARCHAR NOT NULL constraint pk primary key (oid DESC, code DESC))";
+Object[][] insertedRows = new Object[][]{{"o1", "1"}, {"o2", "2"}, 
{"o3", "3"}};
+runQueryTest(ddl, upsert("oid", "code"), insertedRows, new 
Object[][]{{"o2", "2"}, {"o1", "1"}}, new WhereCondition("(oid, code)", "IN", 
"(('o2', '2'), ('o1', '1'))"),
+table);
+}
+
 @Test
 public void likeDescCompositePK1() throws Exception {
 String table = generateUniqueName();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/0d01a3cd/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
index 15f6e3e..9bb7234 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
@@ -199,8 +199,8 @@ public class RowValueConstructorExpression extends 
BaseCompoundExpression {
 // as otherwise we need it to ensure sort order is correct
 for (int k = expressionCount -1 ; 
 k >=0 &&  getChildren().get(k).getDataType() != 
null 
-  && 
!getChildren().get(k).getDataType().isFixedWidth() 
-  && outputBytes[outputSize-1] == 
QueryConstants.SEPARATOR_BYTE ; k--) {
+  && 
!getChildren().get(k).getDataType().isFixedWidth()
+  && outputBytes[outputSize-1] == 
SchemaUtil.getSeparatorByte(true, false, getChildren().get(k)) ; k--) {
 outputSize--;
 }
 ptr.set(outputBytes, 0, outputSize);



[2/9] phoenix git commit: PHOENIX-4322 DESC primary key column with variable length does not work in SkipScanFilter

2018-03-13 Thread maryannxue
PHOENIX-4322 DESC primary key column with variable length does not work in 
SkipScanFilter


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

Branch: refs/heads/4.x-HBase-0.98
Commit: 92b57c7893c91d90d78e30171e233043dbcb4583
Parents: 541d6ac
Author: maryannxue <maryann@gmail.com>
Authored: Tue Dec 5 10:59:41 2017 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Tue Mar 13 17:16:42 2018 -0700

--
 .../it/java/org/apache/phoenix/end2end/SortOrderIT.java  | 11 ++-
 .../expression/RowValueConstructorExpression.java|  4 ++--
 2 files changed, 12 insertions(+), 3 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/92b57c78/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
index 655dbb1..3f749c1 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
@@ -167,7 +167,16 @@ public class SortOrderIT extends ParallelStatsDisabledIT {
 runQueryTest(ddl, upsert("oid", "code"), insertedRows, new 
Object[][]{{"o2", 2}}, new WhereCondition("oid", "IN", "('o2')"),
 table);
 }
-
+
+@Test
+public void inDescCompositePK3() throws Exception {
+String table = generateUniqueName();
+String ddl = "CREATE table " + table + " (oid VARCHAR NOT NULL, code 
VARCHAR NOT NULL constraint pk primary key (oid DESC, code DESC))";
+Object[][] insertedRows = new Object[][]{{"o1", "1"}, {"o2", "2"}, 
{"o3", "3"}};
+runQueryTest(ddl, upsert("oid", "code"), insertedRows, new 
Object[][]{{"o2", "2"}, {"o1", "1"}}, new WhereCondition("(oid, code)", "IN", 
"(('o2', '2'), ('o1', '1'))"),
+table);
+}
+
 @Test
 public void likeDescCompositePK1() throws Exception {
 String table = generateUniqueName();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/92b57c78/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
index 15f6e3e..9bb7234 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
@@ -199,8 +199,8 @@ public class RowValueConstructorExpression extends 
BaseCompoundExpression {
 // as otherwise we need it to ensure sort order is correct
 for (int k = expressionCount -1 ; 
 k >=0 &&  getChildren().get(k).getDataType() != 
null 
-  && 
!getChildren().get(k).getDataType().isFixedWidth() 
-  && outputBytes[outputSize-1] == 
QueryConstants.SEPARATOR_BYTE ; k--) {
+  && 
!getChildren().get(k).getDataType().isFixedWidth()
+  && outputBytes[outputSize-1] == 
SchemaUtil.getSeparatorByte(true, false, getChildren().get(k)) ; k--) {
 outputSize--;
 }
 ptr.set(outputBytes, 0, outputSize);



[8/9] phoenix git commit: PHOENIX-4585 Prune local index regions used for join queries

2018-03-13 Thread maryannxue
PHOENIX-4585 Prune local index regions used for join queries


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

Branch: refs/heads/4.x-HBase-0.98
Commit: babda3258921fdf4de595ba734d972860d58a0a4
Parents: 6914d54
Author: maryannxue <maryann@gmail.com>
Authored: Fri Feb 16 11:29:25 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Tue Mar 13 21:31:00 2018 -0700

--
 .../apache/phoenix/compile/JoinCompiler.java|  37 ++--
 .../apache/phoenix/compile/QueryCompiler.java   |  60 +++---
 .../phoenix/compile/QueryCompilerTest.java  | 186 ++-
 3 files changed, 238 insertions(+), 45 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/babda325/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
index f5a7e39..4020cf9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
@@ -1199,7 +1199,8 @@ public class JoinCompiler {
 return AndExpression.create(expressions);
 }
 
-public static SelectStatement optimize(PhoenixStatement statement, 
SelectStatement select, final ColumnResolver resolver) throws SQLException {
+public static Pair<SelectStatement, Map<TableRef, QueryPlan>> optimize(
+PhoenixStatement statement, SelectStatement select, final 
ColumnResolver resolver) throws SQLException {
 TableRef groupByTableRef = null;
 TableRef orderByTableRef = null;
 if (select.getGroupBy() != null && !select.getGroupBy().isEmpty()) {
@@ -1226,7 +1227,7 @@ public class JoinCompiler {
 QueryCompiler compiler = new QueryCompiler(statement, select, 
resolver, false, null);
 List binds = statement.getParameters();
 StatementContext ctx = new StatementContext(statement, resolver, 
new Scan(), new SequenceManager(statement));
-QueryPlan plan = compiler.compileJoinQuery(ctx, binds, join, 
false, false, null);
+QueryPlan plan = compiler.compileJoinQuery(ctx, binds, join, 
false, false, null, Collections.<TableRef, QueryPlan>emptyMap());
 TableRef table = plan.getTableRef();
 if (groupByTableRef != null && !groupByTableRef.equals(table)) {
 groupByTableRef = null;
@@ -1236,7 +1237,8 @@ public class JoinCompiler {
 }
 }
 
-final Map<TableRef, TableRef> replacement = new HashMap<TableRef, 
TableRef>();
+Map<TableRef, TableRef> replacementMap = null;
+Map<TableRef, QueryPlan> dataPlanMap = null;
 
 for (Table table : join.getTables()) {
 if (table.isSubselect())
@@ -1245,19 +1247,30 @@ public class JoinCompiler {
 List groupBy = tableRef.equals(groupByTableRef) ? 
select.getGroupBy() : null;
 List orderBy = tableRef.equals(orderByTableRef) ? 
select.getOrderBy() : null;
 SelectStatement stmt = 
getSubqueryForOptimizedPlan(select.getHint(), table.getDynamicColumns(), 
table.getTableSamplingRate(), tableRef, join.getColumnRefs(), 
table.getPreFiltersCombined(), groupBy, orderBy, table.isWildCardSelect(), 
select.hasSequence(), select.getUdfParseNodes());
-// TODO: As port of PHOENIX-4585, we need to make sure this plan 
has a pointer to the data plan
-// when an index is used instead of the data table, and that this 
method returns that
-// state for downstream processing.
 // TODO: It seems inefficient to be recompiling the statement 
again and again inside of this optimize call
-QueryPlan plan = 
statement.getConnection().getQueryServices().getOptimizer().optimize(statement, 
stmt);
-if (!plan.getTableRef().equals(tableRef)) {
-replacement.put(tableRef, plan.getTableRef());
+QueryPlan dataPlan =
+new QueryCompiler(
+statement, stmt,
+FromCompiler.getResolverForQuery(stmt, 
statement.getConnection()),
+false, null)
+.compile();
+QueryPlan plan = 
statement.getConnection().getQueryServices().getOptimizer().optimize(statement, 
dataPlan);
+TableRef newTableRef = plan.getTableRef();
+if (!newTa

[3/9] phoenix git commit: PHOENIX-3050 Handle DESC columns in child/parent join optimization

2018-03-13 Thread maryannxue
PHOENIX-3050 Handle DESC columns in child/parent join optimization


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

Branch: refs/heads/4.x-HBase-0.98
Commit: 977699afe0d66f1434b8bc1c5a751767e563d6ce
Parents: 92b57c7
Author: maryannxue <maryann@gmail.com>
Authored: Wed Dec 6 12:07:16 2017 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Tue Mar 13 17:17:16 2018 -0700

--
 .../phoenix/end2end/join/HashJoinMoreIT.java |  5 +
 .../org/apache/phoenix/compile/JoinCompiler.java | 19 +--
 .../apache/phoenix/compile/QueryCompiler.java|  6 +++---
 .../apache/phoenix/compile/WhereOptimizer.java   |  5 -
 4 files changed, 21 insertions(+), 14 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/977699af/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
index 37ffd02..f09f1d3 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
@@ -895,6 +895,11 @@ public class HashJoinMoreIT extends 
ParallelStatsDisabledIT {
 + "FROM ( SELECT ACCOUNT_ID, BUCKET_ID, OBJECT_ID, 
MAX(OBJECT_VERSION) AS MAXVER "
 + "   FROM test2961 GROUP BY ACCOUNT_ID, BUCKET_ID, 
OBJECT_ID) AS X "
 + "   INNER JOIN test2961 AS OBJ ON X.ACCOUNT_ID = 
OBJ.ACCOUNT_ID AND X.BUCKET_ID = OBJ.BUCKET_ID AND X.OBJECT_ID = OBJ.OBJECT_ID 
AND  X.MAXVER = OBJ.OBJECT_VERSION";
+rs = conn.createStatement().executeQuery("explain " + q);
+String plan = QueryUtil.getExplainPlan(rs);
+String dynamicFilter = "DYNAMIC SERVER FILTER BY (OBJ.ACCOUNT_ID, 
OBJ.BUCKET_ID, OBJ.OBJECT_ID, OBJ.OBJECT_VERSION) IN ((X.ACCOUNT_ID, 
X.BUCKET_ID, X.OBJECT_ID, X.MAXVER))";
+assertTrue("Expected '" + dynamicFilter + "' to be used for the 
query, but got:\n" + plan,
+plan.contains(dynamicFilter));
 rs = conn.createStatement().executeQuery(q);
 assertTrue(rs.next());
 assertEquals("", rs.getString(4));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/977699af/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
index f9d8711..f3c4c24 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
@@ -108,6 +108,12 @@ import com.google.common.collect.Sets;
 
 public class JoinCompiler {
 
+public enum Strategy {
+HASH_BUILD_LEFT,
+HASH_BUILD_RIGHT,
+SORT_MERGE,
+}
+
 public enum ColumnRefType {
 JOINLOCAL,
 GENERAL,
@@ -487,7 +493,7 @@ public class JoinCompiler {
 return dependencies;
 }
 
-public Pair<List, List> 
compileJoinConditions(StatementContext lhsCtx, StatementContext rhsCtx, boolean 
sortExpressions) throws SQLException {
+public Pair<List, List> 
compileJoinConditions(StatementContext lhsCtx, StatementContext rhsCtx, 
Strategy strategy) throws SQLException {
 if (onConditions.isEmpty()) {
 return new Pair<List, List>(
 Collections. 
singletonList(LiteralExpression.newConstant(1)),
@@ -503,15 +509,16 @@ public class JoinCompiler {
 rhsCompiler.reset();
 Expression right = condition.getRHS().accept(rhsCompiler);
 PDataType toType = getCommonType(left.getDataType(), 
right.getDataType());
-if (left.getDataType() != toType || left.getSortOrder() == 
SortOrder.DESC) {
-left = CoerceExpression.create(left, toType, 
SortOrder.ASC, left.getMaxLength());
+SortOrder toSortOrder = strategy == Strategy.SORT_MERGE ? 
SortOrder.ASC : (strategy == Strategy.HASH_BUILD_LEFT ? right.getSortOrder() : 
left.getSortOrder());
+if (left.getDataType() != toType || left.getSortOrder() != 
to

[6/9] phoenix git commit: PHOENIX-1556 Base hash versus sort merge join decision on cost

2018-03-13 Thread maryannxue
http://git-wip-us.apache.org/repos/asf/phoenix/blob/6914d54d/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
index a15ab35..21cbc2d 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
@@ -35,6 +35,10 @@ import org.apache.phoenix.compile.QueryPlan;
 import org.apache.phoenix.compile.RowProjector;
 import org.apache.phoenix.compile.StatementContext;
 import org.apache.phoenix.coprocessor.BaseScannerRegionObserver;
+import org.apache.phoenix.execute.visitor.AvgRowWidthVisitor;
+import org.apache.phoenix.execute.visitor.ByteCountVisitor;
+import org.apache.phoenix.execute.visitor.QueryPlanVisitor;
+import org.apache.phoenix.execute.visitor.RowCountVisitor;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.OrderByExpression;
 import org.apache.phoenix.expression.aggregator.Aggregators;
@@ -90,25 +94,30 @@ public class ClientAggregatePlan extends 
ClientProcessingPlan {
 
 @Override
 public Cost getCost() {
-Long byteCount = null;
-try {
-byteCount = getEstimatedBytesToScan();
-} catch (SQLException e) {
-// ignored.
-}
-
-if (byteCount == null) {
+Double outputBytes = this.accept(new ByteCountVisitor());
+Double inputRows = this.getDelegate().accept(new RowCountVisitor());
+Double rowWidth = this.accept(new AvgRowWidthVisitor());
+if (inputRows == null || outputBytes == null || rowWidth == null) {
 return Cost.UNKNOWN;
 }
+double inputBytes = inputRows * rowWidth;
+double rowsBeforeHaving = RowCountVisitor.aggregate(
+RowCountVisitor.filter(
+inputRows.doubleValue(),
+RowCountVisitor.stripSkipScanFilter(
+context.getScan().getFilter())),
+groupBy);
+double rowsAfterHaving = RowCountVisitor.filter(rowsBeforeHaving, 
having);
+double bytesBeforeHaving = rowWidth * rowsBeforeHaving;
+double bytesAfterHaving = rowWidth * rowsAfterHaving;
 
 int parallelLevel = CostUtil.estimateParallelLevel(
 false, context.getConnection().getQueryServices());
-Cost cost = CostUtil.estimateAggregateCost(byteCount,
-groupBy, clientAggregators.getEstimatedByteSize(), 
parallelLevel);
+Cost cost = CostUtil.estimateAggregateCost(
+inputBytes, bytesBeforeHaving, groupBy, parallelLevel);
 if (!orderBy.getOrderByExpressions().isEmpty()) {
-double outputBytes = CostUtil.estimateAggregateOutputBytes(
-byteCount, groupBy, 
clientAggregators.getEstimatedByteSize());
-Cost orderByCost = CostUtil.estimateOrderByCost(outputBytes, 
parallelLevel);
+Cost orderByCost = CostUtil.estimateOrderByCost(
+bytesAfterHaving, outputBytes, parallelLevel);
 cost = cost.plus(orderByCost);
 }
 return super.getCost().plus(cost);
@@ -210,7 +219,16 @@ public class ClientAggregatePlan extends 
ClientProcessingPlan {
 public GroupBy getGroupBy() {
 return groupBy;
 }
-
+
+@Override
+public  T accept(QueryPlanVisitor visitor) {
+return visitor.visit(this);
+}
+
+public Expression getHaving() {
+return having;
+}
+
 private static class ClientGroupedAggregatingResultIterator extends 
BaseGroupedAggregatingResultIterator {
 private final List groupByExpressions;
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6914d54d/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
index ac43919..75ba8f2 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
@@ -85,4 +85,8 @@ public abstract class ClientProcessingPlan extends 
DelegateQueryPlan {
 public FilterableStatement getStatement() {
 return statement;
 }
+
+public Expression getWhere() {
+return where;
+}
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6914d54d/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientScanPlan.java
--
diff --git 

[7/9] phoenix git commit: PHOENIX-1556 Base hash versus sort merge join decision on cost

2018-03-13 Thread maryannxue
PHOENIX-1556 Base hash versus sort merge join decision on cost


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

Branch: refs/heads/4.x-HBase-0.98
Commit: 6914d54d99b4fafae44d1a3397c44ba6e5d10368
Parents: 2c75823
Author: maryannxue <maryann@gmail.com>
Authored: Mon Feb 12 14:07:30 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Tue Mar 13 21:19:01 2018 -0700

--
 .../phoenix/end2end/CostBasedDecisionIT.java| 420 -
 .../apache/phoenix/compile/JoinCompiler.java|  43 ++
 .../phoenix/compile/ListJarsQueryPlan.java  |   8 +-
 .../apache/phoenix/compile/QueryCompiler.java   | 455 ++-
 .../org/apache/phoenix/compile/QueryPlan.java   |   2 +
 .../apache/phoenix/compile/TraceQueryPlan.java  |   6 +
 .../apache/phoenix/execute/AggregatePlan.java   |  41 +-
 .../phoenix/execute/ClientAggregatePlan.java|  46 +-
 .../phoenix/execute/ClientProcessingPlan.java   |   4 +
 .../apache/phoenix/execute/ClientScanPlan.java  |  22 +-
 .../apache/phoenix/execute/CorrelatePlan.java   |  26 +-
 .../apache/phoenix/execute/CursorFetchPlan.java |   6 +
 .../apache/phoenix/execute/HashJoinPlan.java| 128 --
 .../execute/LiteralResultIterationPlan.java |   6 +
 .../org/apache/phoenix/execute/ScanPlan.java|  14 +-
 .../phoenix/execute/SortMergeJoinPlan.java  |  20 +-
 .../phoenix/execute/TupleProjectionPlan.java|   6 +
 .../org/apache/phoenix/execute/UnionPlan.java   |  12 +-
 .../apache/phoenix/execute/UnnestArrayPlan.java |   6 +
 .../execute/visitor/AvgRowWidthVisitor.java | 205 +
 .../execute/visitor/ByteCountVisitor.java   | 125 +
 .../execute/visitor/QueryPlanVisitor.java   |  46 ++
 .../execute/visitor/RowCountVisitor.java| 335 ++
 .../apache/phoenix/jdbc/PhoenixStatement.java   |   6 +
 .../java/org/apache/phoenix/util/CostUtil.java  |  61 +--
 .../query/ParallelIteratorsSplitTest.java   |   6 +
 26 files changed, 1615 insertions(+), 440 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/6914d54d/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
index a3584ce..493855a 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
@@ -32,12 +32,16 @@ import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.QueryUtil;
 import org.apache.phoenix.util.ReadOnlyProps;
+
 import org.junit.BeforeClass;
 import org.junit.Test;
 
 import com.google.common.collect.Maps;
 
 public class CostBasedDecisionIT extends BaseUniqueNamesOwnClusterIT {
+private final String testTable500;
+private final String testTable990;
+private final String testTable1000;
 
 @BeforeClass
 public static void doSetup() throws Exception {
@@ -46,9 +50,16 @@ public class CostBasedDecisionIT extends 
BaseUniqueNamesOwnClusterIT {
 props.put(QueryServices.STATS_UPDATE_FREQ_MS_ATTRIB, Long.toString(5));
 props.put(QueryServices.USE_STATS_FOR_PARALLELIZATION, 
Boolean.toString(true));
 props.put(QueryServices.COST_BASED_OPTIMIZER_ENABLED, 
Boolean.toString(true));
+props.put(QueryServices.MAX_SERVER_CACHE_SIZE_ATTRIB, 
Long.toString(15));
 setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
 }
 
+public CostBasedDecisionIT() throws Exception {
+testTable500 = initTestTableValues(500);
+testTable990 = initTestTableValues(990);
+testTable1000 = initTestTableValues(1000);
+}
+
 @Test
 public void testCostOverridesStaticPlanOrdering1() throws Exception {
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
@@ -64,10 +75,7 @@ public class CostBasedDecisionIT extends 
BaseUniqueNamesOwnClusterIT {
 
 String query = "SELECT rowkey, c1, c2 FROM " + tableName + " where 
c1 LIKE 'X0%' ORDER BY rowkey";
 // Use the data table plan that opts out order-by when stats are 
not available.
-ResultSet rs = conn.createStatement().executeQuery("explain " + 
query);
-String plan = QueryUtil.getExplainPlan(rs);
-assertTrue("Expected 'FULL SCAN' in the plan:\n" + plan 

[9/9] phoenix git commit: PHOENIX-4611 Not nullable column impact on join query plans

2018-03-13 Thread maryannxue
PHOENIX-4611 Not nullable column impact on join query plans


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

Branch: refs/heads/4.x-HBase-0.98
Commit: 9bb7811f001d00cea42da6185c3645d7d14e4a16
Parents: babda32
Author: maryannxue <maryann@gmail.com>
Authored: Fri Feb 16 21:03:46 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Tue Mar 13 21:31:58 2018 -0700

--
 .../java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java | 8 
 .../java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java | 4 ++--
 .../main/java/org/apache/phoenix/compile/JoinCompiler.java   | 4 
 3 files changed, 10 insertions(+), 6 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/9bb7811f/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
index a132728..dea349a 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
@@ -440,8 +440,8 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 "SERVER AGGREGATE INTO ORDERED DISTINCT ROWS 
BY [BUCKET, \"TIMESTAMP\", SRC_LOCATION, DST_LOCATION]\n" +
 "CLIENT MERGE SORT\n" +
 "CLIENT SORTED BY [BUCKET, \"TIMESTAMP\"]\n" +
-"CLIENT SORTED BY [E.BUCKET, E.TIMESTAMP]\n" +
-"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.BUCKET, 
E.TIMESTAMP]"
+"CLIENT SORTED BY [E.TIMESTAMP, E.BUCKET]\n" +
+"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.TIMESTAMP, 
E.BUCKET]"
 :
 "SORT-MERGE-JOIN (INNER) TABLES\n" +
 "CLIENT PARALLEL 2-WAY SKIP SCAN ON 2 RANGES OVER 
" + eventCountTableName + " [0,'5SEC',~14629935200,'Tr/Bal'] - 
[1,'5SEC',~14629934200,'Tr/Bal']\n" +
@@ -456,8 +456,8 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 "SERVER DISTINCT PREFIX FILTER OVER [BUCKET, 
\"TIMESTAMP\", SRC_LOCATION, DST_LOCATION]\n" +
 "SERVER AGGREGATE INTO ORDERED DISTINCT ROWS 
BY [BUCKET, \"TIMESTAMP\", SRC_LOCATION, DST_LOCATION]\n" +
 "CLIENT MERGE SORT\n" +
-"CLIENT SORTED BY [E.BUCKET, E.TIMESTAMP]\n" +
-"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.BUCKET, 
E.TIMESTAMP]";
+"CLIENT SORTED BY [E.TIMESTAMP, E.BUCKET]\n" +
+"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.TIMESTAMP, 
E.BUCKET]";
 
 ResultSet rs = conn.createStatement().executeQuery("explain " 
+ q);
 assertEquals(p, QueryUtil.getExplainPlan(rs));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9bb7811f/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
index f09f1d3..3a1b015 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
@@ -786,7 +786,7 @@ public class HashJoinMoreIT extends ParallelStatsDisabledIT 
{
 String p = i == 0 ?
 "CLIENT PARALLEL 2-WAY SKIP SCAN ON 2 RANGES OVER 
EVENT_COUNT [0,'5SEC',~14629935200,'Tr/Bal'] - 
[1,'5SEC',~14629934200,'Tr/Bal']\n" +
 "SERVER FILTER BY FIRST KEY ONLY\n" +
-"SERVER AGGREGATE INTO DISTINCT ROWS BY [E.BUCKET, 
\"E.TIMESTAMP\"]\n" +
+"SERVER AGGREGATE INTO DISTINCT ROWS BY 
[\"E.TIMESTAMP\", E.BUCKET]\n" +
 "CLIENT MERGE SORT\n" +

[1/9] phoenix git commit: PHOENIX-4288 Indexes not used when ordering by primary key

2018-03-13 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 1e83415f1 -> 9bb7811f0


PHOENIX-4288 Indexes not used when ordering by primary key


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

Branch: refs/heads/4.x-HBase-0.98
Commit: 541d6ac22866fe7571365e063a23108c6ca1ea63
Parents: 1e83415
Author: maryannxue <maryann@gmail.com>
Authored: Tue Dec 5 10:52:46 2017 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Tue Mar 13 17:16:04 2018 -0700

--
 .../phoenix/end2end/CostBasedDecisionIT.java| 466 +++
 .../phoenix/compile/ListJarsQueryPlan.java  |   6 +
 .../org/apache/phoenix/compile/QueryPlan.java   |   5 +-
 .../apache/phoenix/compile/TraceQueryPlan.java  |   6 +
 .../apache/phoenix/execute/AggregatePlan.java   |  30 +-
 .../apache/phoenix/execute/BaseQueryPlan.java   |  19 +-
 .../phoenix/execute/ClientAggregatePlan.java|  28 ++
 .../apache/phoenix/execute/ClientScanPlan.java  |  25 +
 .../apache/phoenix/execute/CorrelatePlan.java   |  25 +
 .../phoenix/execute/DelegateQueryPlan.java  |   6 +
 .../apache/phoenix/execute/HashJoinPlan.java|  29 ++
 .../execute/LiteralResultIterationPlan.java |   6 +
 .../org/apache/phoenix/execute/ScanPlan.java|  25 +
 .../phoenix/execute/SortMergeJoinPlan.java  |  18 +
 .../org/apache/phoenix/execute/UnionPlan.java   |  10 +
 .../apache/phoenix/jdbc/PhoenixStatement.java   |   6 +
 .../java/org/apache/phoenix/optimize/Cost.java  | 123 +
 .../apache/phoenix/optimize/QueryOptimizer.java |  28 +-
 .../org/apache/phoenix/query/QueryServices.java |   2 +
 .../phoenix/query/QueryServicesOptions.java |   6 +-
 .../java/org/apache/phoenix/util/CostUtil.java  |  90 
 .../query/ParallelIteratorsSplitTest.java   |   6 +
 22 files changed, 951 insertions(+), 14 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/541d6ac2/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
new file mode 100644
index 000..a3584ce
--- /dev/null
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
@@ -0,0 +1,466 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end;
+
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.phoenix.query.BaseTest;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.apache.phoenix.util.QueryUtil;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.google.common.collect.Maps;
+
+public class CostBasedDecisionIT extends BaseUniqueNamesOwnClusterIT {
+
+@BeforeClass
+public static void doSetup() throws Exception {
+Map<String, String> props = Maps.newHashMapWithExpectedSize(1);
+props.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, 
Long.toString(20));
+props.put(QueryServices.STATS_UPDATE_FREQ_MS_ATTRIB, Long.toString(5));
+props.put(QueryServices.USE_STATS_FOR_PARALLELIZATION, 
Boolean.toString(true));
+props.put(QueryServices.COST_BASED_OPTIMIZER_ENABLED, 
Boolean.toString(true));
+setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
+}
+
+@Test
+public void testCostOverridesStaticPlanOrdering1() throws Exception {
+Properties props 

[4/9] phoenix git commit: PHOENIX-4437 Make QueryPlan.getEstimatedBytesToScan() independent of getExplainPlan() and pull optimize() out of getExplainPlan()

2018-03-13 Thread maryannxue
PHOENIX-4437 Make QueryPlan.getEstimatedBytesToScan() independent of 
getExplainPlan() and pull optimize() out of getExplainPlan()


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

Branch: refs/heads/4.x-HBase-0.98
Commit: 7ef96fe1bed43f3ac3dae900a3e6a83791faf697
Parents: 977699a
Author: maryannxue <maryann@gmail.com>
Authored: Thu Dec 21 10:31:04 2017 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Tue Mar 13 20:08:24 2018 -0700

--
 .../end2end/ExplainPlanWithStatsEnabledIT.java  |  4 +-
 .../apache/phoenix/execute/BaseQueryPlan.java   | 45 ++
 .../apache/phoenix/execute/HashJoinPlan.java| 59 +-
 .../phoenix/execute/SortMergeJoinPlan.java  | 63 ++--
 .../org/apache/phoenix/execute/UnionPlan.java   | 53 
 .../apache/phoenix/jdbc/PhoenixStatement.java   |  9 ++-
 6 files changed, 120 insertions(+), 113 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/7ef96fe1/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java
index 76ed7ba..a835e84 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java
@@ -303,8 +303,8 @@ public class ExplainPlanWithStatsEnabledIT extends 
ParallelStatsEnabledIT {
 try (Connection conn = DriverManager.getConnection(getUrl())) {
 conn.setAutoCommit(false);
 Estimate info = getByteRowEstimates(conn, sql, binds);
-assertEquals((Long) 200L, info.estimatedBytes);
-assertEquals((Long) 2L, info.estimatedRows);
+assertEquals((Long) 176l, info.estimatedBytes);
+assertEquals((Long) 2l, info.estimatedRows);
 assertTrue(info.estimateInfoTs > 0);
 }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7ef96fe1/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
index 38ed926..c4edf31 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
@@ -118,7 +118,7 @@ public abstract class BaseQueryPlan implements QueryPlan {
 protected Long estimatedRows;
 protected Long estimatedSize;
 protected Long estimateInfoTimestamp;
-private boolean explainPlanCalled;
+private boolean getEstimatesCalled;
 
 
 protected BaseQueryPlan(
@@ -500,32 +500,17 @@ public abstract class BaseQueryPlan implements QueryPlan {
 
 @Override
 public ExplainPlan getExplainPlan() throws SQLException {
-explainPlanCalled = true;
 if (context.getScanRanges() == ScanRanges.NOTHING) {
 return new ExplainPlan(Collections.singletonList("DEGENERATE SCAN 
OVER " + getTableRef().getTable().getName().getString()));
 }
 
-// If cost-based optimizer is enabled, we need to initialize a dummy 
iterator to
-// get the stats for computing costs.
-boolean costBased =
-
context.getConnection().getQueryServices().getConfiguration().getBoolean(
-QueryServices.COST_BASED_OPTIMIZER_ENABLED, 
QueryServicesOptions.DEFAULT_COST_BASED_OPTIMIZER_ENABLED);
-if (costBased) {
-ResultIterator iterator = iterator();
-iterator.close();
-}
-// Optimize here when getting explain plan, as queries don't get 
optimized until after compilation
-QueryPlan plan = 
context.getConnection().getQueryServices().getOptimizer().optimize(context.getStatement(),
 this);
-ExplainPlan exp = plan instanceof BaseQueryPlan ? new 
ExplainPlan(getPlanSteps(plan.iterator())) : plan.getExplainPlan();
-if (!costBased) { // do not override estimates if they are used for 
cost calculation.
-this.estimatedRows = plan.getEstimatedRowsToScan();
-this.estimatedSize = plan.getEstimatedBytesToScan();
-this.estimateInfoTimestamp = plan.getEstimateInfoTimestamp();
-}
-return exp

[5/9] phoenix git commit: PHOENIX-3505 Avoid NPE on close() in OrderedResultIterator

2018-03-13 Thread maryannxue
PHOENIX-3505 Avoid NPE on close() in OrderedResultIterator


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

Branch: refs/heads/4.x-HBase-0.98
Commit: 2c758234186e5a4d70cdc6501df19f9b0d9ec601
Parents: 7ef96fe
Author: Josh Elser <els...@apache.org>
Authored: Wed Nov 23 11:16:35 2016 -0500
Committer: maryannxue <maryann@gmail.com>
Committed: Tue Mar 13 20:08:46 2018 -0700

--
 .../phoenix/iterate/OrderedResultIterator.java  |  5 ++-
 .../iterate/OrderedResultIteratorTest.java  | 41 
 2 files changed, 45 insertions(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/2c758234/phoenix-core/src/main/java/org/apache/phoenix/iterate/OrderedResultIterator.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/iterate/OrderedResultIterator.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/iterate/OrderedResultIterator.java
index 36ca00b..36b274a 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/iterate/OrderedResultIterator.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/iterate/OrderedResultIterator.java
@@ -280,7 +280,10 @@ public class OrderedResultIterator implements 
PeekingResultIterator {
 
 @Override
 public void close() throws SQLException {
-resultIterator.close();
+// Guard against resultIterator being null
+if (null != resultIterator) {
+resultIterator.close();
+}
 resultIterator = PeekingResultIterator.EMPTY_ITERATOR;
 }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/2c758234/phoenix-core/src/test/java/org/apache/phoenix/iterate/OrderedResultIteratorTest.java
--
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/iterate/OrderedResultIteratorTest.java
 
b/phoenix-core/src/test/java/org/apache/phoenix/iterate/OrderedResultIteratorTest.java
new file mode 100644
index 000..50ed8e9
--- /dev/null
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/iterate/OrderedResultIteratorTest.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.iterate;
+
+import java.sql.SQLException;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.phoenix.expression.OrderByExpression;
+import org.junit.Test;
+
+/**
+ * Test class for {@link OrderedResultIterator}.
+ */
+public class OrderedResultIteratorTest {
+
+  @Test
+  public void testNullIteratorOnClose() throws SQLException {
+  ResultIterator delegate =  ResultIterator.EMPTY_ITERATOR;
+  List orderByExpressions = 
Collections.singletonList(null);
+  int thresholdBytes = Integer.MAX_VALUE;
+  OrderedResultIterator iterator = new OrderedResultIterator(delegate, 
orderByExpressions, thresholdBytes);
+  // Should not throw an exception
+  iterator.close();
+  }
+
+}



[8/9] phoenix git commit: PHOENIX-4585 Prune local index regions used for join queries (addendum)

2018-03-13 Thread maryannxue
PHOENIX-4585 Prune local index regions used for join queries (addendum)


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

Branch: refs/heads/4.x-HBase-1.1
Commit: eafcdd1ac7875aca48f869adc29f6f0d88942559
Parents: 4b2659b
Author: maryannxue <maryann@gmail.com>
Authored: Tue Mar 13 17:02:01 2018 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Tue Mar 13 17:02:01 2018 -0700

--
 .../src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java | 1 -
 1 file changed, 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/eafcdd1a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
--
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java 
b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
index 0d5a0ff..1e615c1 100644
--- 
a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryCompilerTest.java
@@ -4728,5 +4728,4 @@ public class QueryCompilerTest extends 
BaseConnectionlessQueryTest {
 return Collections.emptyList();
 }
 }
->>>>>>> 11308c8aa... PHOENIX-4585 Prune local index regions used for join 
queries
 }



[5/9] phoenix git commit: PHOENIX-4585 Prune local index regions used for join queries

2018-03-13 Thread maryannxue
PHOENIX-4585 Prune local index regions used for join queries


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

Branch: refs/heads/4.x-HBase-1.1
Commit: adbce12f90ad3341aa7991bb0445fe1d11cda597
Parents: 6b40a36
Author: maryannxue <maryann@gmail.com>
Authored: Fri Feb 16 11:29:25 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Tue Mar 13 16:54:27 2018 -0700

--
 .../apache/phoenix/compile/JoinCompiler.java|  37 ++--
 .../apache/phoenix/compile/QueryCompiler.java   |  56 +++---
 .../phoenix/compile/QueryCompilerTest.java  | 187 ++-
 3 files changed, 237 insertions(+), 43 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/adbce12f/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
index f5a7e39..4020cf9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
@@ -1199,7 +1199,8 @@ public class JoinCompiler {
 return AndExpression.create(expressions);
 }
 
-public static SelectStatement optimize(PhoenixStatement statement, 
SelectStatement select, final ColumnResolver resolver) throws SQLException {
+public static Pair<SelectStatement, Map<TableRef, QueryPlan>> optimize(
+PhoenixStatement statement, SelectStatement select, final 
ColumnResolver resolver) throws SQLException {
 TableRef groupByTableRef = null;
 TableRef orderByTableRef = null;
 if (select.getGroupBy() != null && !select.getGroupBy().isEmpty()) {
@@ -1226,7 +1227,7 @@ public class JoinCompiler {
 QueryCompiler compiler = new QueryCompiler(statement, select, 
resolver, false, null);
 List binds = statement.getParameters();
 StatementContext ctx = new StatementContext(statement, resolver, 
new Scan(), new SequenceManager(statement));
-QueryPlan plan = compiler.compileJoinQuery(ctx, binds, join, 
false, false, null);
+QueryPlan plan = compiler.compileJoinQuery(ctx, binds, join, 
false, false, null, Collections.<TableRef, QueryPlan>emptyMap());
 TableRef table = plan.getTableRef();
 if (groupByTableRef != null && !groupByTableRef.equals(table)) {
 groupByTableRef = null;
@@ -1236,7 +1237,8 @@ public class JoinCompiler {
 }
 }
 
-final Map<TableRef, TableRef> replacement = new HashMap<TableRef, 
TableRef>();
+Map<TableRef, TableRef> replacementMap = null;
+Map<TableRef, QueryPlan> dataPlanMap = null;
 
 for (Table table : join.getTables()) {
 if (table.isSubselect())
@@ -1245,19 +1247,30 @@ public class JoinCompiler {
 List groupBy = tableRef.equals(groupByTableRef) ? 
select.getGroupBy() : null;
 List orderBy = tableRef.equals(orderByTableRef) ? 
select.getOrderBy() : null;
 SelectStatement stmt = 
getSubqueryForOptimizedPlan(select.getHint(), table.getDynamicColumns(), 
table.getTableSamplingRate(), tableRef, join.getColumnRefs(), 
table.getPreFiltersCombined(), groupBy, orderBy, table.isWildCardSelect(), 
select.hasSequence(), select.getUdfParseNodes());
-// TODO: As port of PHOENIX-4585, we need to make sure this plan 
has a pointer to the data plan
-// when an index is used instead of the data table, and that this 
method returns that
-// state for downstream processing.
 // TODO: It seems inefficient to be recompiling the statement 
again and again inside of this optimize call
-QueryPlan plan = 
statement.getConnection().getQueryServices().getOptimizer().optimize(statement, 
stmt);
-if (!plan.getTableRef().equals(tableRef)) {
-replacement.put(tableRef, plan.getTableRef());
+QueryPlan dataPlan =
+new QueryCompiler(
+statement, stmt,
+FromCompiler.getResolverForQuery(stmt, 
statement.getConnection()),
+false, null)
+.compile();
+QueryPlan plan = 
statement.getConnection().getQueryServices().getOptimizer().optimize(statement, 
dataPlan);
+TableRef newTableRef = plan.getTableRef();
+if (!newTa

[1/9] phoenix git commit: PHOENIX-3050 Handle DESC columns in child/parent join optimization

2018-03-13 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.1 49f19ba68 -> c65c81a47


PHOENIX-3050 Handle DESC columns in child/parent join optimization


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

Branch: refs/heads/4.x-HBase-1.1
Commit: 33ca96e656f3eac2802bcd5d3a5e1e4780455cf5
Parents: 49f19ba
Author: maryannxue <maryann@gmail.com>
Authored: Wed Dec 6 12:07:16 2017 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Tue Mar 13 16:44:33 2018 -0700

--
 .../phoenix/end2end/join/HashJoinMoreIT.java |  5 +
 .../org/apache/phoenix/compile/JoinCompiler.java | 19 +--
 .../apache/phoenix/compile/QueryCompiler.java|  6 +++---
 .../apache/phoenix/compile/WhereOptimizer.java   |  5 -
 4 files changed, 21 insertions(+), 14 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/33ca96e6/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
index 37ffd02..f09f1d3 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
@@ -895,6 +895,11 @@ public class HashJoinMoreIT extends 
ParallelStatsDisabledIT {
 + "FROM ( SELECT ACCOUNT_ID, BUCKET_ID, OBJECT_ID, 
MAX(OBJECT_VERSION) AS MAXVER "
 + "   FROM test2961 GROUP BY ACCOUNT_ID, BUCKET_ID, 
OBJECT_ID) AS X "
 + "   INNER JOIN test2961 AS OBJ ON X.ACCOUNT_ID = 
OBJ.ACCOUNT_ID AND X.BUCKET_ID = OBJ.BUCKET_ID AND X.OBJECT_ID = OBJ.OBJECT_ID 
AND  X.MAXVER = OBJ.OBJECT_VERSION";
+rs = conn.createStatement().executeQuery("explain " + q);
+String plan = QueryUtil.getExplainPlan(rs);
+String dynamicFilter = "DYNAMIC SERVER FILTER BY (OBJ.ACCOUNT_ID, 
OBJ.BUCKET_ID, OBJ.OBJECT_ID, OBJ.OBJECT_VERSION) IN ((X.ACCOUNT_ID, 
X.BUCKET_ID, X.OBJECT_ID, X.MAXVER))";
+assertTrue("Expected '" + dynamicFilter + "' to be used for the 
query, but got:\n" + plan,
+plan.contains(dynamicFilter));
 rs = conn.createStatement().executeQuery(q);
 assertTrue(rs.next());
 assertEquals("", rs.getString(4));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/33ca96e6/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
index f9d8711..f3c4c24 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
@@ -108,6 +108,12 @@ import com.google.common.collect.Sets;
 
 public class JoinCompiler {
 
+public enum Strategy {
+HASH_BUILD_LEFT,
+HASH_BUILD_RIGHT,
+SORT_MERGE,
+}
+
 public enum ColumnRefType {
 JOINLOCAL,
 GENERAL,
@@ -487,7 +493,7 @@ public class JoinCompiler {
 return dependencies;
 }
 
-public Pair<List, List> 
compileJoinConditions(StatementContext lhsCtx, StatementContext rhsCtx, boolean 
sortExpressions) throws SQLException {
+public Pair<List, List> 
compileJoinConditions(StatementContext lhsCtx, StatementContext rhsCtx, 
Strategy strategy) throws SQLException {
 if (onConditions.isEmpty()) {
 return new Pair<List, List>(
 Collections. 
singletonList(LiteralExpression.newConstant(1)),
@@ -503,15 +509,16 @@ public class JoinCompiler {
 rhsCompiler.reset();
 Expression right = condition.getRHS().accept(rhsCompiler);
 PDataType toType = getCommonType(left.getDataType(), 
right.getDataType());
-if (left.getDataType() != toType || left.getSortOrder() == 
SortOrder.DESC) {
-left = CoerceExpression.create(left, toType, 
SortOrder.ASC, left.getMaxLength());
+SortOrder toSortOrder = strategy == Strategy.SORT_MERGE ? 
SortOrder.ASC : (strategy == Strategy.HASH_BUILD_LEFT ? right.getSortOrder() : 
left.getSortOrder());
+   

[9/9] phoenix git commit: PHOENIX-4611 Not nullable column impact on join query plans

2018-03-13 Thread maryannxue
PHOENIX-4611 Not nullable column impact on join query plans


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

Branch: refs/heads/4.x-HBase-1.1
Commit: c65c81a47a65127a60886a984378c268598fd2e0
Parents: eafcdd1
Author: maryannxue <maryann@gmail.com>
Authored: Fri Feb 16 21:03:46 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Tue Mar 13 17:02:13 2018 -0700

--
 .../java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java | 8 
 .../java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java | 4 ++--
 .../main/java/org/apache/phoenix/compile/JoinCompiler.java   | 4 
 .../org/apache/phoenix/compile/TupleProjectionCompiler.java  | 2 +-
 4 files changed, 11 insertions(+), 7 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/c65c81a4/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
index a132728..dea349a 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
@@ -440,8 +440,8 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 "SERVER AGGREGATE INTO ORDERED DISTINCT ROWS 
BY [BUCKET, \"TIMESTAMP\", SRC_LOCATION, DST_LOCATION]\n" +
 "CLIENT MERGE SORT\n" +
 "CLIENT SORTED BY [BUCKET, \"TIMESTAMP\"]\n" +
-"CLIENT SORTED BY [E.BUCKET, E.TIMESTAMP]\n" +
-"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.BUCKET, 
E.TIMESTAMP]"
+"CLIENT SORTED BY [E.TIMESTAMP, E.BUCKET]\n" +
+"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.TIMESTAMP, 
E.BUCKET]"
 :
 "SORT-MERGE-JOIN (INNER) TABLES\n" +
 "CLIENT PARALLEL 2-WAY SKIP SCAN ON 2 RANGES OVER 
" + eventCountTableName + " [0,'5SEC',~14629935200,'Tr/Bal'] - 
[1,'5SEC',~14629934200,'Tr/Bal']\n" +
@@ -456,8 +456,8 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 "SERVER DISTINCT PREFIX FILTER OVER [BUCKET, 
\"TIMESTAMP\", SRC_LOCATION, DST_LOCATION]\n" +
 "SERVER AGGREGATE INTO ORDERED DISTINCT ROWS 
BY [BUCKET, \"TIMESTAMP\", SRC_LOCATION, DST_LOCATION]\n" +
 "CLIENT MERGE SORT\n" +
-"CLIENT SORTED BY [E.BUCKET, E.TIMESTAMP]\n" +
-"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.BUCKET, 
E.TIMESTAMP]";
+"CLIENT SORTED BY [E.TIMESTAMP, E.BUCKET]\n" +
+"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.TIMESTAMP, 
E.BUCKET]";
 
 ResultSet rs = conn.createStatement().executeQuery("explain " 
+ q);
 assertEquals(p, QueryUtil.getExplainPlan(rs));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/c65c81a4/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
index f09f1d3..3a1b015 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
@@ -786,7 +786,7 @@ public class HashJoinMoreIT extends ParallelStatsDisabledIT 
{
 String p = i == 0 ?
 "CLIENT PARALLEL 2-WAY SKIP SCAN ON 2 RANGES OVER 
EVENT_COUNT [0,'5SEC',~14629935200,'Tr/Bal'] - 
[1,'5SEC',~14629934200,'Tr/Bal']\n" +
 "SERVER FILTER BY FIRST KEY ONLY\n" +
-"SERVER AGGREGATE INTO DISTINCT ROWS BY [E.BUCKET, 
\"E.TIMESTAMP\"]\n" +
+"SERVER AGGREGATE INTO DISTINCT ROWS BY 
[\"E.TIMESTAMP\", E.BUCKET]\n" +

[7/9] phoenix git commit: Revert "PHOENIX-4611 Not nullable column impact on join query plans"

2018-03-13 Thread maryannxue
Revert "PHOENIX-4611 Not nullable column impact on join query plans"


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

Branch: refs/heads/4.x-HBase-1.1
Commit: 4b2659b85ed3a68722a81d4ff7a6b8fdda9b79ed
Parents: 8162813
Author: maryannxue <maryann@gmail.com>
Authored: Tue Mar 13 16:59:05 2018 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Tue Mar 13 16:59:05 2018 -0700

--
 .../java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java | 8 
 .../java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java | 4 ++--
 .../main/java/org/apache/phoenix/compile/JoinCompiler.java   | 4 
 .../org/apache/phoenix/compile/TupleProjectionCompiler.java  | 2 +-
 4 files changed, 7 insertions(+), 11 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/4b2659b8/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
index dea349a..a132728 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
@@ -440,8 +440,8 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 "SERVER AGGREGATE INTO ORDERED DISTINCT ROWS 
BY [BUCKET, \"TIMESTAMP\", SRC_LOCATION, DST_LOCATION]\n" +
 "CLIENT MERGE SORT\n" +
 "CLIENT SORTED BY [BUCKET, \"TIMESTAMP\"]\n" +
-"CLIENT SORTED BY [E.TIMESTAMP, E.BUCKET]\n" +
-"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.TIMESTAMP, 
E.BUCKET]"
+"CLIENT SORTED BY [E.BUCKET, E.TIMESTAMP]\n" +
+"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.BUCKET, 
E.TIMESTAMP]"
 :
 "SORT-MERGE-JOIN (INNER) TABLES\n" +
 "CLIENT PARALLEL 2-WAY SKIP SCAN ON 2 RANGES OVER 
" + eventCountTableName + " [0,'5SEC',~14629935200,'Tr/Bal'] - 
[1,'5SEC',~14629934200,'Tr/Bal']\n" +
@@ -456,8 +456,8 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 "SERVER DISTINCT PREFIX FILTER OVER [BUCKET, 
\"TIMESTAMP\", SRC_LOCATION, DST_LOCATION]\n" +
 "SERVER AGGREGATE INTO ORDERED DISTINCT ROWS 
BY [BUCKET, \"TIMESTAMP\", SRC_LOCATION, DST_LOCATION]\n" +
 "CLIENT MERGE SORT\n" +
-"CLIENT SORTED BY [E.TIMESTAMP, E.BUCKET]\n" +
-"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.TIMESTAMP, 
E.BUCKET]";
+"CLIENT SORTED BY [E.BUCKET, E.TIMESTAMP]\n" +
+"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.BUCKET, 
E.TIMESTAMP]";
 
 ResultSet rs = conn.createStatement().executeQuery("explain " 
+ q);
 assertEquals(p, QueryUtil.getExplainPlan(rs));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/4b2659b8/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
index 3a1b015..f09f1d3 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
@@ -786,7 +786,7 @@ public class HashJoinMoreIT extends ParallelStatsDisabledIT 
{
 String p = i == 0 ?
 "CLIENT PARALLEL 2-WAY SKIP SCAN ON 2 RANGES OVER 
EVENT_COUNT [0,'5SEC',~14629935200,'Tr/Bal'] - 
[1,'5SEC',~14629934200,'Tr/Bal']\n" +
 "SERVER FILTER BY FIRST KEY ONLY\n" +
-"SERVER AGGREGATE INTO DISTINCT ROWS BY 
[\"E.TIMESTAMP\", E.BUCKET]\n" +
+"SERVER AGGREGATE INTO DISTINCT ROWS BY [E.BUCKET, 
\"E.TIMESTAMP\"]\n" +
  

[3/9] phoenix git commit: PHOENIX-1556 Base hash versus sort merge join decision on cost

2018-03-13 Thread maryannxue
http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b40a36b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
index a15ab35..21cbc2d 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
@@ -35,6 +35,10 @@ import org.apache.phoenix.compile.QueryPlan;
 import org.apache.phoenix.compile.RowProjector;
 import org.apache.phoenix.compile.StatementContext;
 import org.apache.phoenix.coprocessor.BaseScannerRegionObserver;
+import org.apache.phoenix.execute.visitor.AvgRowWidthVisitor;
+import org.apache.phoenix.execute.visitor.ByteCountVisitor;
+import org.apache.phoenix.execute.visitor.QueryPlanVisitor;
+import org.apache.phoenix.execute.visitor.RowCountVisitor;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.OrderByExpression;
 import org.apache.phoenix.expression.aggregator.Aggregators;
@@ -90,25 +94,30 @@ public class ClientAggregatePlan extends 
ClientProcessingPlan {
 
 @Override
 public Cost getCost() {
-Long byteCount = null;
-try {
-byteCount = getEstimatedBytesToScan();
-} catch (SQLException e) {
-// ignored.
-}
-
-if (byteCount == null) {
+Double outputBytes = this.accept(new ByteCountVisitor());
+Double inputRows = this.getDelegate().accept(new RowCountVisitor());
+Double rowWidth = this.accept(new AvgRowWidthVisitor());
+if (inputRows == null || outputBytes == null || rowWidth == null) {
 return Cost.UNKNOWN;
 }
+double inputBytes = inputRows * rowWidth;
+double rowsBeforeHaving = RowCountVisitor.aggregate(
+RowCountVisitor.filter(
+inputRows.doubleValue(),
+RowCountVisitor.stripSkipScanFilter(
+context.getScan().getFilter())),
+groupBy);
+double rowsAfterHaving = RowCountVisitor.filter(rowsBeforeHaving, 
having);
+double bytesBeforeHaving = rowWidth * rowsBeforeHaving;
+double bytesAfterHaving = rowWidth * rowsAfterHaving;
 
 int parallelLevel = CostUtil.estimateParallelLevel(
 false, context.getConnection().getQueryServices());
-Cost cost = CostUtil.estimateAggregateCost(byteCount,
-groupBy, clientAggregators.getEstimatedByteSize(), 
parallelLevel);
+Cost cost = CostUtil.estimateAggregateCost(
+inputBytes, bytesBeforeHaving, groupBy, parallelLevel);
 if (!orderBy.getOrderByExpressions().isEmpty()) {
-double outputBytes = CostUtil.estimateAggregateOutputBytes(
-byteCount, groupBy, 
clientAggregators.getEstimatedByteSize());
-Cost orderByCost = CostUtil.estimateOrderByCost(outputBytes, 
parallelLevel);
+Cost orderByCost = CostUtil.estimateOrderByCost(
+bytesAfterHaving, outputBytes, parallelLevel);
 cost = cost.plus(orderByCost);
 }
 return super.getCost().plus(cost);
@@ -210,7 +219,16 @@ public class ClientAggregatePlan extends 
ClientProcessingPlan {
 public GroupBy getGroupBy() {
 return groupBy;
 }
-
+
+@Override
+public  T accept(QueryPlanVisitor visitor) {
+return visitor.visit(this);
+}
+
+public Expression getHaving() {
+return having;
+}
+
 private static class ClientGroupedAggregatingResultIterator extends 
BaseGroupedAggregatingResultIterator {
 private final List groupByExpressions;
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b40a36b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
index ac43919..75ba8f2 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
@@ -85,4 +85,8 @@ public abstract class ClientProcessingPlan extends 
DelegateQueryPlan {
 public FilterableStatement getStatement() {
 return statement;
 }
+
+public Expression getWhere() {
+return where;
+}
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b40a36b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientScanPlan.java
--
diff --git 

[2/9] phoenix git commit: PHOENIX-4437 Make QueryPlan.getEstimatedBytesToScan() independent of getExplainPlan() and pull optimize() out of getExplainPlan()

2018-03-13 Thread maryannxue
PHOENIX-4437 Make QueryPlan.getEstimatedBytesToScan() independent of 
getExplainPlan() and pull optimize() out of getExplainPlan()


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

Branch: refs/heads/4.x-HBase-1.1
Commit: 56cdcb9043a8e10933428b2145b0d57b58d3e284
Parents: 33ca96e
Author: maryannxue <maryann@gmail.com>
Authored: Thu Dec 21 10:31:04 2017 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Tue Mar 13 16:47:25 2018 -0700

--
 .../end2end/ExplainPlanWithStatsEnabledIT.java  |  4 +-
 .../apache/phoenix/execute/BaseQueryPlan.java   | 45 ++
 .../apache/phoenix/execute/HashJoinPlan.java| 59 +-
 .../phoenix/execute/SortMergeJoinPlan.java  | 63 ++--
 .../org/apache/phoenix/execute/UnionPlan.java   | 53 
 .../apache/phoenix/jdbc/PhoenixStatement.java   |  9 ++-
 6 files changed, 120 insertions(+), 113 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/56cdcb90/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java
index 969bbfb..39bdb67 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java
@@ -303,8 +303,8 @@ public class ExplainPlanWithStatsEnabledIT extends 
ParallelStatsEnabledIT {
 try (Connection conn = DriverManager.getConnection(getUrl())) {
 conn.setAutoCommit(false);
 Estimate info = getByteRowEstimates(conn, sql, binds);
-assertEquals((Long) 200L, info.estimatedBytes);
-assertEquals((Long) 2L, info.estimatedRows);
+assertEquals((Long) 176l, info.estimatedBytes);
+assertEquals((Long) 2l, info.estimatedRows);
 assertTrue(info.estimateInfoTs > 0);
 }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/56cdcb90/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
index 968b259..b152030 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
@@ -118,7 +118,7 @@ public abstract class BaseQueryPlan implements QueryPlan {
 protected Long estimatedRows;
 protected Long estimatedSize;
 protected Long estimateInfoTimestamp;
-private boolean explainPlanCalled;
+private boolean getEstimatesCalled;
 
 
 protected BaseQueryPlan(
@@ -506,32 +506,17 @@ public abstract class BaseQueryPlan implements QueryPlan {
 
 @Override
 public ExplainPlan getExplainPlan() throws SQLException {
-explainPlanCalled = true;
 if (context.getScanRanges() == ScanRanges.NOTHING) {
 return new ExplainPlan(Collections.singletonList("DEGENERATE SCAN 
OVER " + getTableRef().getTable().getName().getString()));
 }
 
-// If cost-based optimizer is enabled, we need to initialize a dummy 
iterator to
-// get the stats for computing costs.
-boolean costBased =
-
context.getConnection().getQueryServices().getConfiguration().getBoolean(
-QueryServices.COST_BASED_OPTIMIZER_ENABLED, 
QueryServicesOptions.DEFAULT_COST_BASED_OPTIMIZER_ENABLED);
-if (costBased) {
-ResultIterator iterator = iterator();
-iterator.close();
-}
-// Optimize here when getting explain plan, as queries don't get 
optimized until after compilation
-QueryPlan plan = 
context.getConnection().getQueryServices().getOptimizer().optimize(context.getStatement(),
 this);
-ExplainPlan exp = plan instanceof BaseQueryPlan ? new 
ExplainPlan(getPlanSteps(plan.iterator())) : plan.getExplainPlan();
-if (!costBased) { // do not override estimates if they are used for 
cost calculation.
-this.estimatedRows = plan.getEstimatedRowsToScan();
-this.estimatedSize = plan.getEstimatedBytesToScan();
-this.estimateInfoTimestamp = plan.getEstimateInfoTimestamp();
-}
-return exp

[4/9] phoenix git commit: PHOENIX-1556 Base hash versus sort merge join decision on cost

2018-03-13 Thread maryannxue
PHOENIX-1556 Base hash versus sort merge join decision on cost


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

Branch: refs/heads/4.x-HBase-1.1
Commit: 6b40a36b51eb92361dc2cfdca291f4391c7fcc01
Parents: 56cdcb9
Author: maryannxue <maryann@gmail.com>
Authored: Mon Feb 12 14:07:30 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Tue Mar 13 16:48:01 2018 -0700

--
 .../phoenix/end2end/CostBasedDecisionIT.java| 420 -
 .../apache/phoenix/compile/JoinCompiler.java|  43 ++
 .../phoenix/compile/ListJarsQueryPlan.java  |   8 +-
 .../apache/phoenix/compile/QueryCompiler.java   | 449 ++-
 .../org/apache/phoenix/compile/QueryPlan.java   |   2 +
 .../apache/phoenix/compile/TraceQueryPlan.java  |   6 +
 .../apache/phoenix/execute/AggregatePlan.java   |  41 +-
 .../phoenix/execute/ClientAggregatePlan.java|  46 +-
 .../phoenix/execute/ClientProcessingPlan.java   |   4 +
 .../apache/phoenix/execute/ClientScanPlan.java  |  22 +-
 .../apache/phoenix/execute/CorrelatePlan.java   |  26 +-
 .../apache/phoenix/execute/CursorFetchPlan.java |   6 +
 .../apache/phoenix/execute/HashJoinPlan.java| 128 --
 .../execute/LiteralResultIterationPlan.java |   6 +
 .../org/apache/phoenix/execute/ScanPlan.java|  14 +-
 .../phoenix/execute/SortMergeJoinPlan.java  |  20 +-
 .../phoenix/execute/TupleProjectionPlan.java|   6 +
 .../org/apache/phoenix/execute/UnionPlan.java   |  12 +-
 .../apache/phoenix/execute/UnnestArrayPlan.java |   6 +
 .../execute/visitor/AvgRowWidthVisitor.java | 205 +
 .../execute/visitor/ByteCountVisitor.java   | 125 ++
 .../execute/visitor/QueryPlanVisitor.java   |  46 ++
 .../execute/visitor/RowCountVisitor.java| 335 ++
 .../apache/phoenix/jdbc/PhoenixStatement.java   |   6 +
 .../java/org/apache/phoenix/util/CostUtil.java  |  61 +--
 .../query/ParallelIteratorsSplitTest.java   |   6 +
 26 files changed, 1612 insertions(+), 437 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/6b40a36b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
index a3584ce..493855a 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
@@ -32,12 +32,16 @@ import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.QueryUtil;
 import org.apache.phoenix.util.ReadOnlyProps;
+
 import org.junit.BeforeClass;
 import org.junit.Test;
 
 import com.google.common.collect.Maps;
 
 public class CostBasedDecisionIT extends BaseUniqueNamesOwnClusterIT {
+private final String testTable500;
+private final String testTable990;
+private final String testTable1000;
 
 @BeforeClass
 public static void doSetup() throws Exception {
@@ -46,9 +50,16 @@ public class CostBasedDecisionIT extends 
BaseUniqueNamesOwnClusterIT {
 props.put(QueryServices.STATS_UPDATE_FREQ_MS_ATTRIB, Long.toString(5));
 props.put(QueryServices.USE_STATS_FOR_PARALLELIZATION, 
Boolean.toString(true));
 props.put(QueryServices.COST_BASED_OPTIMIZER_ENABLED, 
Boolean.toString(true));
+props.put(QueryServices.MAX_SERVER_CACHE_SIZE_ATTRIB, 
Long.toString(15));
 setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
 }
 
+public CostBasedDecisionIT() throws Exception {
+testTable500 = initTestTableValues(500);
+testTable990 = initTestTableValues(990);
+testTable1000 = initTestTableValues(1000);
+}
+
 @Test
 public void testCostOverridesStaticPlanOrdering1() throws Exception {
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
@@ -64,10 +75,7 @@ public class CostBasedDecisionIT extends 
BaseUniqueNamesOwnClusterIT {
 
 String query = "SELECT rowkey, c1, c2 FROM " + tableName + " where 
c1 LIKE 'X0%' ORDER BY rowkey";
 // Use the data table plan that opts out order-by when stats are 
not available.
-ResultSet rs = conn.createStatement().executeQuery("explain " + 
query);
-String plan = QueryUtil.getExplainPlan(rs);
-assertTrue("Expected 'FULL SCAN' in the plan:\n" + plan 

[6/9] phoenix git commit: PHOENIX-4611 Not nullable column impact on join query plans

2018-03-13 Thread maryannxue
PHOENIX-4611 Not nullable column impact on join query plans


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

Branch: refs/heads/4.x-HBase-1.1
Commit: 8162813ffac3003dc70dca5c40a3386ea7a1cbbc
Parents: adbce12
Author: maryannxue <maryann@gmail.com>
Authored: Fri Feb 16 21:03:46 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Tue Mar 13 16:55:16 2018 -0700

--
 .../java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java | 8 
 .../java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java | 4 ++--
 .../main/java/org/apache/phoenix/compile/JoinCompiler.java   | 4 
 .../org/apache/phoenix/compile/TupleProjectionCompiler.java  | 2 +-
 4 files changed, 11 insertions(+), 7 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/8162813f/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
index a132728..dea349a 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
@@ -440,8 +440,8 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 "SERVER AGGREGATE INTO ORDERED DISTINCT ROWS 
BY [BUCKET, \"TIMESTAMP\", SRC_LOCATION, DST_LOCATION]\n" +
 "CLIENT MERGE SORT\n" +
 "CLIENT SORTED BY [BUCKET, \"TIMESTAMP\"]\n" +
-"CLIENT SORTED BY [E.BUCKET, E.TIMESTAMP]\n" +
-"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.BUCKET, 
E.TIMESTAMP]"
+"CLIENT SORTED BY [E.TIMESTAMP, E.BUCKET]\n" +
+"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.TIMESTAMP, 
E.BUCKET]"
 :
 "SORT-MERGE-JOIN (INNER) TABLES\n" +
 "CLIENT PARALLEL 2-WAY SKIP SCAN ON 2 RANGES OVER 
" + eventCountTableName + " [0,'5SEC',~14629935200,'Tr/Bal'] - 
[1,'5SEC',~14629934200,'Tr/Bal']\n" +
@@ -456,8 +456,8 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 "SERVER DISTINCT PREFIX FILTER OVER [BUCKET, 
\"TIMESTAMP\", SRC_LOCATION, DST_LOCATION]\n" +
 "SERVER AGGREGATE INTO ORDERED DISTINCT ROWS 
BY [BUCKET, \"TIMESTAMP\", SRC_LOCATION, DST_LOCATION]\n" +
 "CLIENT MERGE SORT\n" +
-"CLIENT SORTED BY [E.BUCKET, E.TIMESTAMP]\n" +
-"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.BUCKET, 
E.TIMESTAMP]";
+"CLIENT SORTED BY [E.TIMESTAMP, E.BUCKET]\n" +
+"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.TIMESTAMP, 
E.BUCKET]";
 
 ResultSet rs = conn.createStatement().executeQuery("explain " 
+ q);
 assertEquals(p, QueryUtil.getExplainPlan(rs));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/8162813f/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
index f09f1d3..3a1b015 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
@@ -786,7 +786,7 @@ public class HashJoinMoreIT extends ParallelStatsDisabledIT 
{
 String p = i == 0 ?
 "CLIENT PARALLEL 2-WAY SKIP SCAN ON 2 RANGES OVER 
EVENT_COUNT [0,'5SEC',~14629935200,'Tr/Bal'] - 
[1,'5SEC',~14629934200,'Tr/Bal']\n" +
 "SERVER FILTER BY FIRST KEY ONLY\n" +
-"SERVER AGGREGATE INTO DISTINCT ROWS BY [E.BUCKET, 
\"E.TIMESTAMP\"]\n" +
+"SERVER AGGREGATE INTO DISTINCT ROWS BY 
[\"E.TIMESTAMP\", E.BUCKET]\n" +

phoenix git commit: PHOENIX-4288 Indexes not used when ordering by primary key

2018-03-13 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.1 20f4cf99f -> 49f19ba68


PHOENIX-4288 Indexes not used when ordering by primary key


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

Branch: refs/heads/4.x-HBase-1.1
Commit: 49f19ba684457a6208985d52900da9081fdce7d6
Parents: 20f4cf9
Author: maryannxue <maryann@gmail.com>
Authored: Tue Dec 5 10:52:46 2017 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Tue Mar 13 16:43:01 2018 -0700

--
 .../phoenix/end2end/CostBasedDecisionIT.java| 466 +++
 .../phoenix/compile/ListJarsQueryPlan.java  |   6 +
 .../org/apache/phoenix/compile/QueryPlan.java   |   5 +-
 .../apache/phoenix/compile/TraceQueryPlan.java  |   6 +
 .../apache/phoenix/execute/AggregatePlan.java   |  30 +-
 .../apache/phoenix/execute/BaseQueryPlan.java   |  19 +-
 .../phoenix/execute/ClientAggregatePlan.java|  28 ++
 .../apache/phoenix/execute/ClientScanPlan.java  |  25 +
 .../apache/phoenix/execute/CorrelatePlan.java   |  25 +
 .../phoenix/execute/DelegateQueryPlan.java  |   6 +
 .../apache/phoenix/execute/HashJoinPlan.java|  29 ++
 .../execute/LiteralResultIterationPlan.java |   6 +
 .../org/apache/phoenix/execute/ScanPlan.java|  25 +
 .../phoenix/execute/SortMergeJoinPlan.java  |  18 +
 .../org/apache/phoenix/execute/UnionPlan.java   |  10 +
 .../apache/phoenix/jdbc/PhoenixStatement.java   |   6 +
 .../java/org/apache/phoenix/optimize/Cost.java  | 123 +
 .../apache/phoenix/optimize/QueryOptimizer.java |  28 +-
 .../org/apache/phoenix/query/QueryServices.java |   2 +
 .../phoenix/query/QueryServicesOptions.java |   6 +-
 .../java/org/apache/phoenix/util/CostUtil.java  |  90 
 .../query/ParallelIteratorsSplitTest.java   |   6 +
 22 files changed, 951 insertions(+), 14 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/49f19ba6/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
new file mode 100644
index 000..a3584ce
--- /dev/null
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
@@ -0,0 +1,466 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end;
+
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.phoenix.query.BaseTest;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.apache.phoenix.util.QueryUtil;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.google.common.collect.Maps;
+
+public class CostBasedDecisionIT extends BaseUniqueNamesOwnClusterIT {
+
+@BeforeClass
+public static void doSetup() throws Exception {
+Map<String, String> props = Maps.newHashMapWithExpectedSize(1);
+props.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, 
Long.toString(20));
+props.put(QueryServices.STATS_UPDATE_FREQ_MS_ATTRIB, Long.toString(5));
+props.put(QueryServices.USE_STATS_FOR_PARALLELIZATION, 
Boolean.toString(true));
+props.put(QueryServices.COST_BASED_OPTIMIZER_ENABLED, 
Boolean.toString(true));
+setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
+}
+
+@Test
+public void testCostOverridesStaticPlanOrdering1() throws Exception {
+Properties props 

phoenix git commit: PHOENIX-4611 Not nullable column impact on join query plans

2018-02-19 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/5.x-HBase-2.0 11308c8aa -> 6cadbab92


PHOENIX-4611 Not nullable column impact on join query plans


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

Branch: refs/heads/5.x-HBase-2.0
Commit: 6cadbab92f5b063c0cf6e07f36175f0475260aad
Parents: 11308c8
Author: maryannxue <maryann@gmail.com>
Authored: Fri Feb 16 21:03:46 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Mon Feb 19 23:08:47 2018 -0800

--
 .../java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java | 8 
 .../java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java | 4 ++--
 .../main/java/org/apache/phoenix/compile/JoinCompiler.java   | 4 
 .../org/apache/phoenix/compile/TupleProjectionCompiler.java  | 2 +-
 4 files changed, 11 insertions(+), 7 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/6cadbab9/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
index a132728..dea349a 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
@@ -440,8 +440,8 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 "SERVER AGGREGATE INTO ORDERED DISTINCT ROWS 
BY [BUCKET, \"TIMESTAMP\", SRC_LOCATION, DST_LOCATION]\n" +
 "CLIENT MERGE SORT\n" +
 "CLIENT SORTED BY [BUCKET, \"TIMESTAMP\"]\n" +
-"CLIENT SORTED BY [E.BUCKET, E.TIMESTAMP]\n" +
-"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.BUCKET, 
E.TIMESTAMP]"
+"CLIENT SORTED BY [E.TIMESTAMP, E.BUCKET]\n" +
+"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.TIMESTAMP, 
E.BUCKET]"
 :
 "SORT-MERGE-JOIN (INNER) TABLES\n" +
 "CLIENT PARALLEL 2-WAY SKIP SCAN ON 2 RANGES OVER 
" + eventCountTableName + " [0,'5SEC',~14629935200,'Tr/Bal'] - 
[1,'5SEC',~14629934200,'Tr/Bal']\n" +
@@ -456,8 +456,8 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 "SERVER DISTINCT PREFIX FILTER OVER [BUCKET, 
\"TIMESTAMP\", SRC_LOCATION, DST_LOCATION]\n" +
 "SERVER AGGREGATE INTO ORDERED DISTINCT ROWS 
BY [BUCKET, \"TIMESTAMP\", SRC_LOCATION, DST_LOCATION]\n" +
 "CLIENT MERGE SORT\n" +
-"CLIENT SORTED BY [E.BUCKET, E.TIMESTAMP]\n" +
-"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.BUCKET, 
E.TIMESTAMP]";
+"CLIENT SORTED BY [E.TIMESTAMP, E.BUCKET]\n" +
+"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.TIMESTAMP, 
E.BUCKET]";
 
 ResultSet rs = conn.createStatement().executeQuery("explain " 
+ q);
 assertEquals(p, QueryUtil.getExplainPlan(rs));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/6cadbab9/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
index f09f1d3..3a1b015 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
@@ -786,7 +786,7 @@ public class HashJoinMoreIT extends ParallelStatsDisabledIT 
{
 String p = i == 0 ?
 "CLIENT PARALLEL 2-WAY SKIP SCAN ON 2 RANGES OVER 
EVENT_COUNT [0,'5SEC',~14629935200,'Tr/Bal'] - 
[1,'5SEC',~14629934200,'Tr/Bal']\n" +
 "SERVER FILTER BY FIRST KEY ONLY\n" +
-"SERVER AGGREGATE INTO DISTINCT ROWS BY [E.BUCKET, 
\"E.TIMESTAMP\"]\n" +
+"SERVER AGGREGATE 

phoenix git commit: PHOENIX-4585 Prune local index regions used for join queries

2018-02-19 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/5.x-HBase-2.0 71537ed63 -> 11308c8aa


PHOENIX-4585 Prune local index regions used for join queries


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

Branch: refs/heads/5.x-HBase-2.0
Commit: 11308c8aa85777fab73159f963b5d6e357ca3992
Parents: 71537ed
Author: maryannxue <maryann@gmail.com>
Authored: Fri Feb 16 11:29:25 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Mon Feb 19 23:05:01 2018 -0800

--
 .../apache/phoenix/compile/JoinCompiler.java|  37 ++--
 .../apache/phoenix/compile/QueryCompiler.java   |  56 +++---
 .../phoenix/compile/QueryCompilerTest.java  | 187 ++-
 3 files changed, 237 insertions(+), 43 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/11308c8a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
index f5a7e39..4020cf9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
@@ -1199,7 +1199,8 @@ public class JoinCompiler {
 return AndExpression.create(expressions);
 }
 
-public static SelectStatement optimize(PhoenixStatement statement, 
SelectStatement select, final ColumnResolver resolver) throws SQLException {
+public static Pair<SelectStatement, Map<TableRef, QueryPlan>> optimize(
+PhoenixStatement statement, SelectStatement select, final 
ColumnResolver resolver) throws SQLException {
 TableRef groupByTableRef = null;
 TableRef orderByTableRef = null;
 if (select.getGroupBy() != null && !select.getGroupBy().isEmpty()) {
@@ -1226,7 +1227,7 @@ public class JoinCompiler {
 QueryCompiler compiler = new QueryCompiler(statement, select, 
resolver, false, null);
 List binds = statement.getParameters();
 StatementContext ctx = new StatementContext(statement, resolver, 
new Scan(), new SequenceManager(statement));
-QueryPlan plan = compiler.compileJoinQuery(ctx, binds, join, 
false, false, null);
+QueryPlan plan = compiler.compileJoinQuery(ctx, binds, join, 
false, false, null, Collections.<TableRef, QueryPlan>emptyMap());
 TableRef table = plan.getTableRef();
 if (groupByTableRef != null && !groupByTableRef.equals(table)) {
 groupByTableRef = null;
@@ -1236,7 +1237,8 @@ public class JoinCompiler {
 }
 }
 
-final Map<TableRef, TableRef> replacement = new HashMap<TableRef, 
TableRef>();
+Map<TableRef, TableRef> replacementMap = null;
+Map<TableRef, QueryPlan> dataPlanMap = null;
 
 for (Table table : join.getTables()) {
 if (table.isSubselect())
@@ -1245,19 +1247,30 @@ public class JoinCompiler {
 List groupBy = tableRef.equals(groupByTableRef) ? 
select.getGroupBy() : null;
 List orderBy = tableRef.equals(orderByTableRef) ? 
select.getOrderBy() : null;
 SelectStatement stmt = 
getSubqueryForOptimizedPlan(select.getHint(), table.getDynamicColumns(), 
table.getTableSamplingRate(), tableRef, join.getColumnRefs(), 
table.getPreFiltersCombined(), groupBy, orderBy, table.isWildCardSelect(), 
select.hasSequence(), select.getUdfParseNodes());
-// TODO: As port of PHOENIX-4585, we need to make sure this plan 
has a pointer to the data plan
-// when an index is used instead of the data table, and that this 
method returns that
-// state for downstream processing.
 // TODO: It seems inefficient to be recompiling the statement 
again and again inside of this optimize call
-QueryPlan plan = 
statement.getConnection().getQueryServices().getOptimizer().optimize(statement, 
stmt);
-if (!plan.getTableRef().equals(tableRef)) {
-replacement.put(tableRef, plan.getTableRef());
+QueryPlan dataPlan =
+new QueryCompiler(
+statement, stmt,
+FromCompiler.getResolverForQuery(stmt, 
statement.getConnection()),
+false, null)
+.compile();
+QueryPlan plan = 
statement.getConnection().getQueryServices().getOptimizer().optimize(st

[2/2] phoenix git commit: PHOENIX-1556 Base hash versus sort merge join decision on cost

2018-02-19 Thread maryannxue
PHOENIX-1556 Base hash versus sort merge join decision on cost


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

Branch: refs/heads/5.x-HBase-2.0
Commit: 71537ed63d1bffbbc60c43e7c6592c9bce279786
Parents: f0b31ce
Author: maryannxue <maryann@gmail.com>
Authored: Mon Feb 12 14:07:30 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Mon Feb 19 22:48:36 2018 -0800

--
 .../phoenix/end2end/CostBasedDecisionIT.java| 420 -
 .../apache/phoenix/compile/JoinCompiler.java|  43 ++
 .../phoenix/compile/ListJarsQueryPlan.java  |   8 +-
 .../apache/phoenix/compile/QueryCompiler.java   | 449 ++-
 .../org/apache/phoenix/compile/QueryPlan.java   |   2 +
 .../apache/phoenix/compile/TraceQueryPlan.java  |   6 +
 .../apache/phoenix/execute/AggregatePlan.java   |  41 +-
 .../phoenix/execute/ClientAggregatePlan.java|  46 +-
 .../phoenix/execute/ClientProcessingPlan.java   |   4 +
 .../apache/phoenix/execute/ClientScanPlan.java  |  22 +-
 .../apache/phoenix/execute/CorrelatePlan.java   |  26 +-
 .../apache/phoenix/execute/CursorFetchPlan.java |   6 +
 .../apache/phoenix/execute/HashJoinPlan.java| 128 --
 .../execute/LiteralResultIterationPlan.java |   6 +
 .../org/apache/phoenix/execute/ScanPlan.java|  14 +-
 .../phoenix/execute/SortMergeJoinPlan.java  |  20 +-
 .../phoenix/execute/TupleProjectionPlan.java|   6 +
 .../org/apache/phoenix/execute/UnionPlan.java   |  12 +-
 .../apache/phoenix/execute/UnnestArrayPlan.java |   6 +
 .../execute/visitor/AvgRowWidthVisitor.java | 205 +
 .../execute/visitor/ByteCountVisitor.java   | 125 ++
 .../execute/visitor/QueryPlanVisitor.java   |  46 ++
 .../execute/visitor/RowCountVisitor.java| 335 ++
 .../apache/phoenix/jdbc/PhoenixStatement.java   |   6 +
 .../java/org/apache/phoenix/util/CostUtil.java  |  61 +--
 .../query/ParallelIteratorsSplitTest.java   |   6 +
 26 files changed, 1612 insertions(+), 437 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/71537ed6/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
index a3584ce..493855a 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
@@ -32,12 +32,16 @@ import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.QueryUtil;
 import org.apache.phoenix.util.ReadOnlyProps;
+
 import org.junit.BeforeClass;
 import org.junit.Test;
 
 import com.google.common.collect.Maps;
 
 public class CostBasedDecisionIT extends BaseUniqueNamesOwnClusterIT {
+private final String testTable500;
+private final String testTable990;
+private final String testTable1000;
 
 @BeforeClass
 public static void doSetup() throws Exception {
@@ -46,9 +50,16 @@ public class CostBasedDecisionIT extends 
BaseUniqueNamesOwnClusterIT {
 props.put(QueryServices.STATS_UPDATE_FREQ_MS_ATTRIB, Long.toString(5));
 props.put(QueryServices.USE_STATS_FOR_PARALLELIZATION, 
Boolean.toString(true));
 props.put(QueryServices.COST_BASED_OPTIMIZER_ENABLED, 
Boolean.toString(true));
+props.put(QueryServices.MAX_SERVER_CACHE_SIZE_ATTRIB, 
Long.toString(15));
 setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
 }
 
+public CostBasedDecisionIT() throws Exception {
+testTable500 = initTestTableValues(500);
+testTable990 = initTestTableValues(990);
+testTable1000 = initTestTableValues(1000);
+}
+
 @Test
 public void testCostOverridesStaticPlanOrdering1() throws Exception {
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
@@ -64,10 +75,7 @@ public class CostBasedDecisionIT extends 
BaseUniqueNamesOwnClusterIT {
 
 String query = "SELECT rowkey, c1, c2 FROM " + tableName + " where 
c1 LIKE 'X0%' ORDER BY rowkey";
 // Use the data table plan that opts out order-by when stats are 
not available.
-ResultSet rs = conn.createStatement().executeQuery("explain " + 
query);
-String plan = QueryUtil.getExplainPlan(rs);
-assertTrue("Expected 'FULL SCAN' in the plan:\n" + plan 

[1/2] phoenix git commit: PHOENIX-1556 Base hash versus sort merge join decision on cost

2018-02-19 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/5.x-HBase-2.0 f0b31ce19 -> 71537ed63


http://git-wip-us.apache.org/repos/asf/phoenix/blob/71537ed6/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
index 00a92eb..22570e4 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
@@ -34,6 +34,10 @@ import org.apache.phoenix.compile.QueryPlan;
 import org.apache.phoenix.compile.RowProjector;
 import org.apache.phoenix.compile.StatementContext;
 import org.apache.phoenix.coprocessor.BaseScannerRegionObserver;
+import org.apache.phoenix.execute.visitor.AvgRowWidthVisitor;
+import org.apache.phoenix.execute.visitor.ByteCountVisitor;
+import org.apache.phoenix.execute.visitor.QueryPlanVisitor;
+import org.apache.phoenix.execute.visitor.RowCountVisitor;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.OrderByExpression;
 import org.apache.phoenix.expression.aggregator.Aggregators;
@@ -89,25 +93,30 @@ public class ClientAggregatePlan extends 
ClientProcessingPlan {
 
 @Override
 public Cost getCost() {
-Long byteCount = null;
-try {
-byteCount = getEstimatedBytesToScan();
-} catch (SQLException e) {
-// ignored.
-}
-
-if (byteCount == null) {
+Double outputBytes = this.accept(new ByteCountVisitor());
+Double inputRows = this.getDelegate().accept(new RowCountVisitor());
+Double rowWidth = this.accept(new AvgRowWidthVisitor());
+if (inputRows == null || outputBytes == null || rowWidth == null) {
 return Cost.UNKNOWN;
 }
+double inputBytes = inputRows * rowWidth;
+double rowsBeforeHaving = RowCountVisitor.aggregate(
+RowCountVisitor.filter(
+inputRows.doubleValue(),
+RowCountVisitor.stripSkipScanFilter(
+context.getScan().getFilter())),
+groupBy);
+double rowsAfterHaving = RowCountVisitor.filter(rowsBeforeHaving, 
having);
+double bytesBeforeHaving = rowWidth * rowsBeforeHaving;
+double bytesAfterHaving = rowWidth * rowsAfterHaving;
 
 int parallelLevel = CostUtil.estimateParallelLevel(
 false, context.getConnection().getQueryServices());
-Cost cost = CostUtil.estimateAggregateCost(byteCount,
-groupBy, clientAggregators.getEstimatedByteSize(), 
parallelLevel);
+Cost cost = CostUtil.estimateAggregateCost(
+inputBytes, bytesBeforeHaving, groupBy, parallelLevel);
 if (!orderBy.getOrderByExpressions().isEmpty()) {
-double outputBytes = CostUtil.estimateAggregateOutputBytes(
-byteCount, groupBy, 
clientAggregators.getEstimatedByteSize());
-Cost orderByCost = CostUtil.estimateOrderByCost(outputBytes, 
parallelLevel);
+Cost orderByCost = CostUtil.estimateOrderByCost(
+bytesAfterHaving, outputBytes, parallelLevel);
 cost = cost.plus(orderByCost);
 }
 return super.getCost().plus(cost);
@@ -209,7 +218,16 @@ public class ClientAggregatePlan extends 
ClientProcessingPlan {
 public GroupBy getGroupBy() {
 return groupBy;
 }
-
+
+@Override
+public  T accept(QueryPlanVisitor visitor) {
+return visitor.visit(this);
+}
+
+public Expression getHaving() {
+return having;
+}
+
 private static class ClientGroupedAggregatingResultIterator extends 
BaseGroupedAggregatingResultIterator {
 private final List groupByExpressions;
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/71537ed6/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
index ac43919..75ba8f2 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
@@ -85,4 +85,8 @@ public abstract class ClientProcessingPlan extends 
DelegateQueryPlan {
 public FilterableStatement getStatement() {
 return statement;
 }
+
+public Expression getWhere() {
+return where;
+}
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/71537ed6/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientScanPlan.java

phoenix git commit: PHOENIX-4437 Make QueryPlan.getEstimatedBytesToScan() independent of getExplainPlan() and pull optimize() out of getExplainPlan()

2018-02-19 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/5.x-HBase-2.0 b2da76c6d -> f0b31ce19


PHOENIX-4437 Make QueryPlan.getEstimatedBytesToScan() independent of 
getExplainPlan() and pull optimize() out of getExplainPlan()


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

Branch: refs/heads/5.x-HBase-2.0
Commit: f0b31ce19c7704756fa3ab314c0b35a72c323349
Parents: b2da76c
Author: maryannxue <maryann@gmail.com>
Authored: Thu Dec 21 10:31:04 2017 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Mon Feb 19 22:38:54 2018 -0800

--
 .../end2end/ExplainPlanWithStatsEnabledIT.java  |  2 +-
 .../apache/phoenix/execute/BaseQueryPlan.java   | 45 ++
 .../apache/phoenix/execute/HashJoinPlan.java| 59 +-
 .../phoenix/execute/SortMergeJoinPlan.java  | 63 ++--
 .../org/apache/phoenix/execute/UnionPlan.java   | 53 
 .../apache/phoenix/jdbc/PhoenixStatement.java   |  9 ++-
 6 files changed, 119 insertions(+), 112 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/f0b31ce1/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java
index c227b48..fc544cb 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java
@@ -304,7 +304,7 @@ public class ExplainPlanWithStatsEnabledIT extends 
ParallelStatsEnabledIT {
 try (Connection conn = DriverManager.getConnection(getUrl())) {
 conn.setAutoCommit(false);
 Estimate info = getByteRowEstimates(conn, sql, binds);
-assertEquals((Long) 200l, info.estimatedBytes);
+assertEquals((Long) 176l, info.estimatedBytes);
 assertEquals((Long) 2l, info.estimatedRows);
 assertTrue(info.estimateInfoTs > 0);
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/f0b31ce1/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
index 5f0a094..a7a5552 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
@@ -118,7 +118,7 @@ public abstract class BaseQueryPlan implements QueryPlan {
 protected Long estimatedRows;
 protected Long estimatedSize;
 protected Long estimateInfoTimestamp;
-private boolean explainPlanCalled;
+private boolean getEstimatesCalled;
 
 
 protected BaseQueryPlan(
@@ -500,32 +500,17 @@ public abstract class BaseQueryPlan implements QueryPlan {
 
 @Override
 public ExplainPlan getExplainPlan() throws SQLException {
-explainPlanCalled = true;
 if (context.getScanRanges() == ScanRanges.NOTHING) {
 return new ExplainPlan(Collections.singletonList("DEGENERATE SCAN 
OVER " + getTableRef().getTable().getName().getString()));
 }
 
-// If cost-based optimizer is enabled, we need to initialize a dummy 
iterator to
-// get the stats for computing costs.
-boolean costBased =
-
context.getConnection().getQueryServices().getConfiguration().getBoolean(
-QueryServices.COST_BASED_OPTIMIZER_ENABLED, 
QueryServicesOptions.DEFAULT_COST_BASED_OPTIMIZER_ENABLED);
-if (costBased) {
-ResultIterator iterator = iterator();
-iterator.close();
-}
-// Optimize here when getting explain plan, as queries don't get 
optimized until after compilation
-QueryPlan plan = 
context.getConnection().getQueryServices().getOptimizer().optimize(context.getStatement(),
 this);
-ExplainPlan exp = plan instanceof BaseQueryPlan ? new 
ExplainPlan(getPlanSteps(plan.iterator())) : plan.getExplainPlan();
-if (!costBased) { // do not override estimates if they are used for 
cost calculation.
-this.estimatedRows = plan.getEstimatedRowsToScan();
-this.estimatedSize = plan.getEstimatedBytesToScan();
-this.estimateInfoTimestamp = plan.getEstimateInfoTimestamp();
- 

phoenix git commit: PHOENIX-3050 Handle DESC columns in child/parent join optimization

2018-02-19 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/5.x-HBase-2.0 e26be0d37 -> b2da76c6d


PHOENIX-3050 Handle DESC columns in child/parent join optimization


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

Branch: refs/heads/5.x-HBase-2.0
Commit: b2da76c6d77d97d9a4d199a4a0351c948d2fa79f
Parents: e26be0d
Author: maryannxue <maryann@gmail.com>
Authored: Wed Dec 6 12:07:16 2017 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Mon Feb 19 22:29:40 2018 -0800

--
 .../phoenix/end2end/join/HashJoinMoreIT.java |  5 +
 .../org/apache/phoenix/compile/JoinCompiler.java | 19 +--
 .../apache/phoenix/compile/QueryCompiler.java|  6 +++---
 .../apache/phoenix/compile/WhereOptimizer.java   |  5 -
 4 files changed, 21 insertions(+), 14 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/b2da76c6/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
index 37ffd02..f09f1d3 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
@@ -895,6 +895,11 @@ public class HashJoinMoreIT extends 
ParallelStatsDisabledIT {
 + "FROM ( SELECT ACCOUNT_ID, BUCKET_ID, OBJECT_ID, 
MAX(OBJECT_VERSION) AS MAXVER "
 + "   FROM test2961 GROUP BY ACCOUNT_ID, BUCKET_ID, 
OBJECT_ID) AS X "
 + "   INNER JOIN test2961 AS OBJ ON X.ACCOUNT_ID = 
OBJ.ACCOUNT_ID AND X.BUCKET_ID = OBJ.BUCKET_ID AND X.OBJECT_ID = OBJ.OBJECT_ID 
AND  X.MAXVER = OBJ.OBJECT_VERSION";
+rs = conn.createStatement().executeQuery("explain " + q);
+String plan = QueryUtil.getExplainPlan(rs);
+String dynamicFilter = "DYNAMIC SERVER FILTER BY (OBJ.ACCOUNT_ID, 
OBJ.BUCKET_ID, OBJ.OBJECT_ID, OBJ.OBJECT_VERSION) IN ((X.ACCOUNT_ID, 
X.BUCKET_ID, X.OBJECT_ID, X.MAXVER))";
+assertTrue("Expected '" + dynamicFilter + "' to be used for the 
query, but got:\n" + plan,
+plan.contains(dynamicFilter));
 rs = conn.createStatement().executeQuery(q);
 assertTrue(rs.next());
 assertEquals("", rs.getString(4));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b2da76c6/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
index f9d8711..f3c4c24 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
@@ -108,6 +108,12 @@ import com.google.common.collect.Sets;
 
 public class JoinCompiler {
 
+public enum Strategy {
+HASH_BUILD_LEFT,
+HASH_BUILD_RIGHT,
+SORT_MERGE,
+}
+
 public enum ColumnRefType {
 JOINLOCAL,
 GENERAL,
@@ -487,7 +493,7 @@ public class JoinCompiler {
 return dependencies;
 }
 
-public Pair<List, List> 
compileJoinConditions(StatementContext lhsCtx, StatementContext rhsCtx, boolean 
sortExpressions) throws SQLException {
+public Pair<List, List> 
compileJoinConditions(StatementContext lhsCtx, StatementContext rhsCtx, 
Strategy strategy) throws SQLException {
 if (onConditions.isEmpty()) {
 return new Pair<List, List>(
 Collections. 
singletonList(LiteralExpression.newConstant(1)),
@@ -503,15 +509,16 @@ public class JoinCompiler {
 rhsCompiler.reset();
 Expression right = condition.getRHS().accept(rhsCompiler);
 PDataType toType = getCommonType(left.getDataType(), 
right.getDataType());
-if (left.getDataType() != toType || left.getSortOrder() == 
SortOrder.DESC) {
-left = CoerceExpression.create(left, toType, 
SortOrder.ASC, left.getMaxLength());
+SortOrder toSortOrder = strategy == Strategy.SORT_MERGE ? 
SortOrder.ASC : (strategy == Strategy.HASH_BUILD_LEFT ? right.getSortOrder() : 
left.getSortOrder());
+   

phoenix git commit: PHOENIX-4322 DESC primary key column with variable length does not work in SkipScanFilter

2018-02-19 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/5.x-HBase-2.0 a61818e88 -> e26be0d37


PHOENIX-4322 DESC primary key column with variable length does not work in 
SkipScanFilter


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

Branch: refs/heads/5.x-HBase-2.0
Commit: e26be0d37bfa31fc7a4e8b8e84ba119a78dd7268
Parents: a61818e
Author: maryannxue <maryann@gmail.com>
Authored: Tue Dec 5 10:59:41 2017 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Mon Feb 19 22:16:37 2018 -0800

--
 .../it/java/org/apache/phoenix/end2end/SortOrderIT.java  | 11 ++-
 .../expression/RowValueConstructorExpression.java|  4 ++--
 2 files changed, 12 insertions(+), 3 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/e26be0d3/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
index 655dbb1..3f749c1 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
@@ -167,7 +167,16 @@ public class SortOrderIT extends ParallelStatsDisabledIT {
 runQueryTest(ddl, upsert("oid", "code"), insertedRows, new 
Object[][]{{"o2", 2}}, new WhereCondition("oid", "IN", "('o2')"),
 table);
 }
-
+
+@Test
+public void inDescCompositePK3() throws Exception {
+String table = generateUniqueName();
+String ddl = "CREATE table " + table + " (oid VARCHAR NOT NULL, code 
VARCHAR NOT NULL constraint pk primary key (oid DESC, code DESC))";
+Object[][] insertedRows = new Object[][]{{"o1", "1"}, {"o2", "2"}, 
{"o3", "3"}};
+runQueryTest(ddl, upsert("oid", "code"), insertedRows, new 
Object[][]{{"o2", "2"}, {"o1", "1"}}, new WhereCondition("(oid, code)", "IN", 
"(('o2', '2'), ('o1', '1'))"),
+table);
+}
+
 @Test
 public void likeDescCompositePK1() throws Exception {
 String table = generateUniqueName();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e26be0d3/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
index 15f6e3e..9bb7234 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
@@ -199,8 +199,8 @@ public class RowValueConstructorExpression extends 
BaseCompoundExpression {
 // as otherwise we need it to ensure sort order is correct
 for (int k = expressionCount -1 ; 
 k >=0 &&  getChildren().get(k).getDataType() != 
null 
-  && 
!getChildren().get(k).getDataType().isFixedWidth() 
-  && outputBytes[outputSize-1] == 
QueryConstants.SEPARATOR_BYTE ; k--) {
+  && 
!getChildren().get(k).getDataType().isFixedWidth()
+  && outputBytes[outputSize-1] == 
SchemaUtil.getSeparatorByte(true, false, getChildren().get(k)) ; k--) {
 outputSize--;
 }
 ptr.set(outputBytes, 0, outputSize);



phoenix git commit: PHOENIX-4288 Indexes not used when ordering by primary key

2018-02-19 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/5.x-HBase-2.0 0d80b3131 -> a61818e88


PHOENIX-4288 Indexes not used when ordering by primary key


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

Branch: refs/heads/5.x-HBase-2.0
Commit: a61818e88f5cef93c81b87ff5b47b2230e61bfb5
Parents: 0d80b31
Author: maryannxue <maryann@gmail.com>
Authored: Tue Dec 5 10:52:46 2017 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Mon Feb 19 22:15:30 2018 -0800

--
 .../phoenix/end2end/CostBasedDecisionIT.java| 466 +++
 .../phoenix/compile/ListJarsQueryPlan.java  |   6 +
 .../org/apache/phoenix/compile/QueryPlan.java   |   5 +-
 .../apache/phoenix/compile/TraceQueryPlan.java  |   6 +
 .../apache/phoenix/execute/AggregatePlan.java   |  30 +-
 .../apache/phoenix/execute/BaseQueryPlan.java   |  21 +-
 .../phoenix/execute/ClientAggregatePlan.java|  28 ++
 .../apache/phoenix/execute/ClientScanPlan.java  |  25 +
 .../apache/phoenix/execute/CorrelatePlan.java   |  25 +
 .../phoenix/execute/DelegateQueryPlan.java  |   6 +
 .../apache/phoenix/execute/HashJoinPlan.java|  29 ++
 .../execute/LiteralResultIterationPlan.java |   6 +
 .../org/apache/phoenix/execute/ScanPlan.java|  25 +
 .../phoenix/execute/SortMergeJoinPlan.java  |  18 +
 .../org/apache/phoenix/execute/UnionPlan.java   |  10 +
 .../apache/phoenix/jdbc/PhoenixStatement.java   |   6 +
 .../java/org/apache/phoenix/optimize/Cost.java  | 123 +
 .../apache/phoenix/optimize/QueryOptimizer.java |  30 +-
 .../org/apache/phoenix/query/QueryServices.java |   3 +
 .../phoenix/query/QueryServicesOptions.java |   6 +-
 .../java/org/apache/phoenix/util/CostUtil.java  |  90 
 .../query/ParallelIteratorsSplitTest.java   |   6 +
 22 files changed, 955 insertions(+), 15 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/a61818e8/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
new file mode 100644
index 000..a3584ce
--- /dev/null
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
@@ -0,0 +1,466 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end;
+
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.phoenix.query.BaseTest;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.apache.phoenix.util.QueryUtil;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.google.common.collect.Maps;
+
+public class CostBasedDecisionIT extends BaseUniqueNamesOwnClusterIT {
+
+@BeforeClass
+public static void doSetup() throws Exception {
+Map<String, String> props = Maps.newHashMapWithExpectedSize(1);
+props.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, 
Long.toString(20));
+props.put(QueryServices.STATS_UPDATE_FREQ_MS_ATTRIB, Long.toString(5));
+props.put(QueryServices.USE_STATS_FOR_PARALLELIZATION, 
Boolean.toString(true));
+props.put(QueryServices.COST_BASED_OPTIMIZER_ENABLED, 
Boolean.toString(true));
+setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
+}
+
+@Test
+public void testCostOverridesStaticPlanOrdering1() throws Exception {
+Properties props 

phoenix git commit: PHOENIX-4611 Not nullable column impact on join query plans

2018-02-16 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.3 39301abca -> 9e5fdab02


PHOENIX-4611 Not nullable column impact on join query plans


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

Branch: refs/heads/4.x-HBase-1.3
Commit: 9e5fdab0282701f54bf5ec6d6fc21ea97d4ac7b4
Parents: 39301ab
Author: maryannxue <maryann@gmail.com>
Authored: Fri Feb 16 21:04:16 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Fri Feb 16 21:04:16 2018 -0800

--
 .../java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java | 8 
 .../java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java | 4 ++--
 .../main/java/org/apache/phoenix/compile/JoinCompiler.java   | 4 
 .../org/apache/phoenix/compile/TupleProjectionCompiler.java  | 2 +-
 4 files changed, 11 insertions(+), 7 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/9e5fdab0/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
index a132728..dea349a 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
@@ -440,8 +440,8 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 "SERVER AGGREGATE INTO ORDERED DISTINCT ROWS 
BY [BUCKET, \"TIMESTAMP\", SRC_LOCATION, DST_LOCATION]\n" +
 "CLIENT MERGE SORT\n" +
 "CLIENT SORTED BY [BUCKET, \"TIMESTAMP\"]\n" +
-"CLIENT SORTED BY [E.BUCKET, E.TIMESTAMP]\n" +
-"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.BUCKET, 
E.TIMESTAMP]"
+"CLIENT SORTED BY [E.TIMESTAMP, E.BUCKET]\n" +
+"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.TIMESTAMP, 
E.BUCKET]"
 :
 "SORT-MERGE-JOIN (INNER) TABLES\n" +
 "CLIENT PARALLEL 2-WAY SKIP SCAN ON 2 RANGES OVER 
" + eventCountTableName + " [0,'5SEC',~14629935200,'Tr/Bal'] - 
[1,'5SEC',~14629934200,'Tr/Bal']\n" +
@@ -456,8 +456,8 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 "SERVER DISTINCT PREFIX FILTER OVER [BUCKET, 
\"TIMESTAMP\", SRC_LOCATION, DST_LOCATION]\n" +
 "SERVER AGGREGATE INTO ORDERED DISTINCT ROWS 
BY [BUCKET, \"TIMESTAMP\", SRC_LOCATION, DST_LOCATION]\n" +
 "CLIENT MERGE SORT\n" +
-"CLIENT SORTED BY [E.BUCKET, E.TIMESTAMP]\n" +
-"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.BUCKET, 
E.TIMESTAMP]";
+"CLIENT SORTED BY [E.TIMESTAMP, E.BUCKET]\n" +
+"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.TIMESTAMP, 
E.BUCKET]";
 
 ResultSet rs = conn.createStatement().executeQuery("explain " 
+ q);
 assertEquals(p, QueryUtil.getExplainPlan(rs));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9e5fdab0/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
index f09f1d3..3a1b015 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
@@ -786,7 +786,7 @@ public class HashJoinMoreIT extends ParallelStatsDisabledIT 
{
 String p = i == 0 ?
 "CLIENT PARALLEL 2-WAY SKIP SCAN ON 2 RANGES OVER 
EVENT_COUNT [0,'5SEC',~14629935200,'Tr/Bal'] - 
[1,'5SEC',~14629934200,'Tr/Bal']\n" +
 "SERVER FILTER BY FIRST KEY ONLY\n" +
-"SERVER AGGREGATE INTO DISTINCT ROWS BY [E.BUCKET, 
\"E.TIMESTAMP\"]\n" +
+"SERVER AGGREGATE 

phoenix git commit: PHOENIX-4611 Not nullable column impact on join query plans

2018-02-16 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.2 4ea0663d3 -> d4c04fae9


PHOENIX-4611 Not nullable column impact on join query plans


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

Branch: refs/heads/4.x-HBase-1.2
Commit: d4c04fae9b83691bf298882f04113012285e8d5d
Parents: 4ea0663
Author: maryannxue <maryann@gmail.com>
Authored: Fri Feb 16 21:02:58 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Fri Feb 16 21:02:58 2018 -0800

--
 .../java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java | 8 
 .../java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java | 4 ++--
 .../main/java/org/apache/phoenix/compile/JoinCompiler.java   | 4 
 .../org/apache/phoenix/compile/TupleProjectionCompiler.java  | 2 +-
 4 files changed, 11 insertions(+), 7 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/d4c04fae/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
index a132728..dea349a 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
@@ -440,8 +440,8 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 "SERVER AGGREGATE INTO ORDERED DISTINCT ROWS 
BY [BUCKET, \"TIMESTAMP\", SRC_LOCATION, DST_LOCATION]\n" +
 "CLIENT MERGE SORT\n" +
 "CLIENT SORTED BY [BUCKET, \"TIMESTAMP\"]\n" +
-"CLIENT SORTED BY [E.BUCKET, E.TIMESTAMP]\n" +
-"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.BUCKET, 
E.TIMESTAMP]"
+"CLIENT SORTED BY [E.TIMESTAMP, E.BUCKET]\n" +
+"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.TIMESTAMP, 
E.BUCKET]"
 :
 "SORT-MERGE-JOIN (INNER) TABLES\n" +
 "CLIENT PARALLEL 2-WAY SKIP SCAN ON 2 RANGES OVER 
" + eventCountTableName + " [0,'5SEC',~14629935200,'Tr/Bal'] - 
[1,'5SEC',~14629934200,'Tr/Bal']\n" +
@@ -456,8 +456,8 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 "SERVER DISTINCT PREFIX FILTER OVER [BUCKET, 
\"TIMESTAMP\", SRC_LOCATION, DST_LOCATION]\n" +
 "SERVER AGGREGATE INTO ORDERED DISTINCT ROWS 
BY [BUCKET, \"TIMESTAMP\", SRC_LOCATION, DST_LOCATION]\n" +
 "CLIENT MERGE SORT\n" +
-"CLIENT SORTED BY [E.BUCKET, E.TIMESTAMP]\n" +
-"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.BUCKET, 
E.TIMESTAMP]";
+"CLIENT SORTED BY [E.TIMESTAMP, E.BUCKET]\n" +
+"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.TIMESTAMP, 
E.BUCKET]";
 
 ResultSet rs = conn.createStatement().executeQuery("explain " 
+ q);
 assertEquals(p, QueryUtil.getExplainPlan(rs));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d4c04fae/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
index f09f1d3..3a1b015 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
@@ -786,7 +786,7 @@ public class HashJoinMoreIT extends ParallelStatsDisabledIT 
{
 String p = i == 0 ?
 "CLIENT PARALLEL 2-WAY SKIP SCAN ON 2 RANGES OVER 
EVENT_COUNT [0,'5SEC',~14629935200,'Tr/Bal'] - 
[1,'5SEC',~14629934200,'Tr/Bal']\n" +
 "SERVER FILTER BY FIRST KEY ONLY\n" +
-"SERVER AGGREGATE INTO DISTINCT ROWS BY [E.BUCKET, 
\"E.TIMESTAMP\"]\n" +
+"SERVER AGGREGATE 

phoenix git commit: PHOENIX-4611 Not nullable column impact on join query plans

2018-02-16 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/master 4eed109b4 -> 10109d55d


PHOENIX-4611 Not nullable column impact on join query plans


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

Branch: refs/heads/master
Commit: 10109d55d4e8d4c69da53fb02e6c9b98d7721ea1
Parents: 4eed109
Author: maryannxue <maryann@gmail.com>
Authored: Fri Feb 16 21:03:46 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Fri Feb 16 21:03:46 2018 -0800

--
 .../java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java | 8 
 .../java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java | 4 ++--
 .../main/java/org/apache/phoenix/compile/JoinCompiler.java   | 4 
 .../org/apache/phoenix/compile/TupleProjectionCompiler.java  | 2 +-
 4 files changed, 11 insertions(+), 7 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/10109d55/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
index a132728..dea349a 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
@@ -440,8 +440,8 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 "SERVER AGGREGATE INTO ORDERED DISTINCT ROWS 
BY [BUCKET, \"TIMESTAMP\", SRC_LOCATION, DST_LOCATION]\n" +
 "CLIENT MERGE SORT\n" +
 "CLIENT SORTED BY [BUCKET, \"TIMESTAMP\"]\n" +
-"CLIENT SORTED BY [E.BUCKET, E.TIMESTAMP]\n" +
-"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.BUCKET, 
E.TIMESTAMP]"
+"CLIENT SORTED BY [E.TIMESTAMP, E.BUCKET]\n" +
+"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.TIMESTAMP, 
E.BUCKET]"
 :
 "SORT-MERGE-JOIN (INNER) TABLES\n" +
 "CLIENT PARALLEL 2-WAY SKIP SCAN ON 2 RANGES OVER 
" + eventCountTableName + " [0,'5SEC',~14629935200,'Tr/Bal'] - 
[1,'5SEC',~14629934200,'Tr/Bal']\n" +
@@ -456,8 +456,8 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 "SERVER DISTINCT PREFIX FILTER OVER [BUCKET, 
\"TIMESTAMP\", SRC_LOCATION, DST_LOCATION]\n" +
 "SERVER AGGREGATE INTO ORDERED DISTINCT ROWS 
BY [BUCKET, \"TIMESTAMP\", SRC_LOCATION, DST_LOCATION]\n" +
 "CLIENT MERGE SORT\n" +
-"CLIENT SORTED BY [E.BUCKET, E.TIMESTAMP]\n" +
-"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.BUCKET, 
E.TIMESTAMP]";
+"CLIENT SORTED BY [E.TIMESTAMP, E.BUCKET]\n" +
+"CLIENT AGGREGATE INTO DISTINCT ROWS BY [E.TIMESTAMP, 
E.BUCKET]";
 
 ResultSet rs = conn.createStatement().executeQuery("explain " 
+ q);
 assertEquals(p, QueryUtil.getExplainPlan(rs));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/10109d55/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
index f09f1d3..3a1b015 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
@@ -786,7 +786,7 @@ public class HashJoinMoreIT extends ParallelStatsDisabledIT 
{
 String p = i == 0 ?
 "CLIENT PARALLEL 2-WAY SKIP SCAN ON 2 RANGES OVER 
EVENT_COUNT [0,'5SEC',~14629935200,'Tr/Bal'] - 
[1,'5SEC',~14629934200,'Tr/Bal']\n" +
 "SERVER FILTER BY FIRST KEY ONLY\n" +
-"SERVER AGGREGATE INTO DISTINCT ROWS BY [E.BUCKET, 
\"E.TIMESTAMP\"]\n" +
+"SERVER AGGREGATE INTO D

phoenix git commit: PHOENIX-4585 Prune local index regions used for join queries

2018-02-16 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.2 c6a10dc69 -> 4ea0663d3


PHOENIX-4585 Prune local index regions used for join queries


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

Branch: refs/heads/4.x-HBase-1.2
Commit: 4ea0663d3b98cc2aec1077ee98322922996a345d
Parents: c6a10dc
Author: maryannxue <maryann@gmail.com>
Authored: Fri Feb 16 11:50:23 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Fri Feb 16 11:50:23 2018 -0800

--
 .../apache/phoenix/compile/JoinCompiler.java|  37 ++--
 .../apache/phoenix/compile/QueryCompiler.java   |  56 +++---
 .../phoenix/compile/QueryCompilerTest.java  | 187 ++-
 3 files changed, 237 insertions(+), 43 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/4ea0663d/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
index f5a7e39..4020cf9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
@@ -1199,7 +1199,8 @@ public class JoinCompiler {
 return AndExpression.create(expressions);
 }
 
-public static SelectStatement optimize(PhoenixStatement statement, 
SelectStatement select, final ColumnResolver resolver) throws SQLException {
+public static Pair<SelectStatement, Map<TableRef, QueryPlan>> optimize(
+PhoenixStatement statement, SelectStatement select, final 
ColumnResolver resolver) throws SQLException {
 TableRef groupByTableRef = null;
 TableRef orderByTableRef = null;
 if (select.getGroupBy() != null && !select.getGroupBy().isEmpty()) {
@@ -1226,7 +1227,7 @@ public class JoinCompiler {
 QueryCompiler compiler = new QueryCompiler(statement, select, 
resolver, false, null);
 List binds = statement.getParameters();
 StatementContext ctx = new StatementContext(statement, resolver, 
new Scan(), new SequenceManager(statement));
-QueryPlan plan = compiler.compileJoinQuery(ctx, binds, join, 
false, false, null);
+QueryPlan plan = compiler.compileJoinQuery(ctx, binds, join, 
false, false, null, Collections.<TableRef, QueryPlan>emptyMap());
 TableRef table = plan.getTableRef();
 if (groupByTableRef != null && !groupByTableRef.equals(table)) {
 groupByTableRef = null;
@@ -1236,7 +1237,8 @@ public class JoinCompiler {
 }
 }
 
-final Map<TableRef, TableRef> replacement = new HashMap<TableRef, 
TableRef>();
+Map<TableRef, TableRef> replacementMap = null;
+Map<TableRef, QueryPlan> dataPlanMap = null;
 
 for (Table table : join.getTables()) {
 if (table.isSubselect())
@@ -1245,19 +1247,30 @@ public class JoinCompiler {
 List groupBy = tableRef.equals(groupByTableRef) ? 
select.getGroupBy() : null;
 List orderBy = tableRef.equals(orderByTableRef) ? 
select.getOrderBy() : null;
 SelectStatement stmt = 
getSubqueryForOptimizedPlan(select.getHint(), table.getDynamicColumns(), 
table.getTableSamplingRate(), tableRef, join.getColumnRefs(), 
table.getPreFiltersCombined(), groupBy, orderBy, table.isWildCardSelect(), 
select.hasSequence(), select.getUdfParseNodes());
-// TODO: As port of PHOENIX-4585, we need to make sure this plan 
has a pointer to the data plan
-// when an index is used instead of the data table, and that this 
method returns that
-// state for downstream processing.
 // TODO: It seems inefficient to be recompiling the statement 
again and again inside of this optimize call
-QueryPlan plan = 
statement.getConnection().getQueryServices().getOptimizer().optimize(statement, 
stmt);
-if (!plan.getTableRef().equals(tableRef)) {
-replacement.put(tableRef, plan.getTableRef());
+QueryPlan dataPlan =
+new QueryCompiler(
+statement, stmt,
+FromCompiler.getResolverForQuery(stmt, 
statement.getConnection()),
+false, null)
+.compile();
+QueryPlan plan = 
statement.getConnection().getQueryServices().getOptimizer().optimize(st

phoenix git commit: PHOENIX-4585 Prune local index regions used for join queries

2018-02-16 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.3 fa7ff4f4e -> 39301abca


PHOENIX-4585 Prune local index regions used for join queries


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

Branch: refs/heads/4.x-HBase-1.3
Commit: 39301abca2732cc93d6fd2e0d98df2911e8e7423
Parents: fa7ff4f
Author: maryannxue <maryann@gmail.com>
Authored: Fri Feb 16 11:45:37 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Fri Feb 16 11:45:37 2018 -0800

--
 .../apache/phoenix/compile/JoinCompiler.java|  37 ++--
 .../apache/phoenix/compile/QueryCompiler.java   |  56 +++---
 .../phoenix/compile/QueryCompilerTest.java  | 187 ++-
 3 files changed, 237 insertions(+), 43 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/39301abc/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
index f5a7e39..4020cf9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
@@ -1199,7 +1199,8 @@ public class JoinCompiler {
 return AndExpression.create(expressions);
 }
 
-public static SelectStatement optimize(PhoenixStatement statement, 
SelectStatement select, final ColumnResolver resolver) throws SQLException {
+public static Pair<SelectStatement, Map<TableRef, QueryPlan>> optimize(
+PhoenixStatement statement, SelectStatement select, final 
ColumnResolver resolver) throws SQLException {
 TableRef groupByTableRef = null;
 TableRef orderByTableRef = null;
 if (select.getGroupBy() != null && !select.getGroupBy().isEmpty()) {
@@ -1226,7 +1227,7 @@ public class JoinCompiler {
 QueryCompiler compiler = new QueryCompiler(statement, select, 
resolver, false, null);
 List binds = statement.getParameters();
 StatementContext ctx = new StatementContext(statement, resolver, 
new Scan(), new SequenceManager(statement));
-QueryPlan plan = compiler.compileJoinQuery(ctx, binds, join, 
false, false, null);
+QueryPlan plan = compiler.compileJoinQuery(ctx, binds, join, 
false, false, null, Collections.<TableRef, QueryPlan>emptyMap());
 TableRef table = plan.getTableRef();
 if (groupByTableRef != null && !groupByTableRef.equals(table)) {
 groupByTableRef = null;
@@ -1236,7 +1237,8 @@ public class JoinCompiler {
 }
 }
 
-final Map<TableRef, TableRef> replacement = new HashMap<TableRef, 
TableRef>();
+Map<TableRef, TableRef> replacementMap = null;
+Map<TableRef, QueryPlan> dataPlanMap = null;
 
 for (Table table : join.getTables()) {
 if (table.isSubselect())
@@ -1245,19 +1247,30 @@ public class JoinCompiler {
 List groupBy = tableRef.equals(groupByTableRef) ? 
select.getGroupBy() : null;
 List orderBy = tableRef.equals(orderByTableRef) ? 
select.getOrderBy() : null;
 SelectStatement stmt = 
getSubqueryForOptimizedPlan(select.getHint(), table.getDynamicColumns(), 
table.getTableSamplingRate(), tableRef, join.getColumnRefs(), 
table.getPreFiltersCombined(), groupBy, orderBy, table.isWildCardSelect(), 
select.hasSequence(), select.getUdfParseNodes());
-// TODO: As port of PHOENIX-4585, we need to make sure this plan 
has a pointer to the data plan
-// when an index is used instead of the data table, and that this 
method returns that
-// state for downstream processing.
 // TODO: It seems inefficient to be recompiling the statement 
again and again inside of this optimize call
-QueryPlan plan = 
statement.getConnection().getQueryServices().getOptimizer().optimize(statement, 
stmt);
-if (!plan.getTableRef().equals(tableRef)) {
-replacement.put(tableRef, plan.getTableRef());
+QueryPlan dataPlan =
+new QueryCompiler(
+statement, stmt,
+FromCompiler.getResolverForQuery(stmt, 
statement.getConnection()),
+false, null)
+.compile();
+QueryPlan plan = 
statement.getConnection().getQueryServices().getOptimizer().optimize(st

phoenix git commit: PHOENIX-4585 Prune local index regions used for join queries

2018-02-16 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/master a9e212e41 -> 4eed109b4


PHOENIX-4585 Prune local index regions used for join queries


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

Branch: refs/heads/master
Commit: 4eed109b4c5429ea0e193428c1a6b1d6b1ba59ea
Parents: a9e212e
Author: maryannxue <maryann@gmail.com>
Authored: Fri Feb 16 11:29:25 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Fri Feb 16 11:29:25 2018 -0800

--
 .../apache/phoenix/compile/JoinCompiler.java|  37 ++--
 .../apache/phoenix/compile/QueryCompiler.java   |  56 +++---
 .../phoenix/compile/QueryCompilerTest.java  | 187 ++-
 3 files changed, 237 insertions(+), 43 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/4eed109b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
index f5a7e39..4020cf9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
@@ -1199,7 +1199,8 @@ public class JoinCompiler {
 return AndExpression.create(expressions);
 }
 
-public static SelectStatement optimize(PhoenixStatement statement, 
SelectStatement select, final ColumnResolver resolver) throws SQLException {
+public static Pair<SelectStatement, Map<TableRef, QueryPlan>> optimize(
+PhoenixStatement statement, SelectStatement select, final 
ColumnResolver resolver) throws SQLException {
 TableRef groupByTableRef = null;
 TableRef orderByTableRef = null;
 if (select.getGroupBy() != null && !select.getGroupBy().isEmpty()) {
@@ -1226,7 +1227,7 @@ public class JoinCompiler {
 QueryCompiler compiler = new QueryCompiler(statement, select, 
resolver, false, null);
 List binds = statement.getParameters();
 StatementContext ctx = new StatementContext(statement, resolver, 
new Scan(), new SequenceManager(statement));
-QueryPlan plan = compiler.compileJoinQuery(ctx, binds, join, 
false, false, null);
+QueryPlan plan = compiler.compileJoinQuery(ctx, binds, join, 
false, false, null, Collections.<TableRef, QueryPlan>emptyMap());
 TableRef table = plan.getTableRef();
 if (groupByTableRef != null && !groupByTableRef.equals(table)) {
 groupByTableRef = null;
@@ -1236,7 +1237,8 @@ public class JoinCompiler {
 }
 }
 
-final Map<TableRef, TableRef> replacement = new HashMap<TableRef, 
TableRef>();
+Map<TableRef, TableRef> replacementMap = null;
+Map<TableRef, QueryPlan> dataPlanMap = null;
 
 for (Table table : join.getTables()) {
 if (table.isSubselect())
@@ -1245,19 +1247,30 @@ public class JoinCompiler {
 List groupBy = tableRef.equals(groupByTableRef) ? 
select.getGroupBy() : null;
 List orderBy = tableRef.equals(orderByTableRef) ? 
select.getOrderBy() : null;
 SelectStatement stmt = 
getSubqueryForOptimizedPlan(select.getHint(), table.getDynamicColumns(), 
table.getTableSamplingRate(), tableRef, join.getColumnRefs(), 
table.getPreFiltersCombined(), groupBy, orderBy, table.isWildCardSelect(), 
select.hasSequence(), select.getUdfParseNodes());
-// TODO: As port of PHOENIX-4585, we need to make sure this plan 
has a pointer to the data plan
-// when an index is used instead of the data table, and that this 
method returns that
-// state for downstream processing.
 // TODO: It seems inefficient to be recompiling the statement 
again and again inside of this optimize call
-QueryPlan plan = 
statement.getConnection().getQueryServices().getOptimizer().optimize(statement, 
stmt);
-if (!plan.getTableRef().equals(tableRef)) {
-replacement.put(tableRef, plan.getTableRef());
+QueryPlan dataPlan =
+new QueryCompiler(
+statement, stmt,
+FromCompiler.getResolverForQuery(stmt, 
statement.getConnection()),
+false, null)
+.compile();
+QueryPlan plan = 
statement.getConnection().getQueryServices().getOptimizer().optimize(st

[1/2] phoenix git commit: PHOENIX-1556 Base hash versus sort merge join decision on cost

2018-02-12 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.2 ff4ad203b -> c73025115


http://git-wip-us.apache.org/repos/asf/phoenix/blob/c7302511/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
index a15ab35..21cbc2d 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
@@ -35,6 +35,10 @@ import org.apache.phoenix.compile.QueryPlan;
 import org.apache.phoenix.compile.RowProjector;
 import org.apache.phoenix.compile.StatementContext;
 import org.apache.phoenix.coprocessor.BaseScannerRegionObserver;
+import org.apache.phoenix.execute.visitor.AvgRowWidthVisitor;
+import org.apache.phoenix.execute.visitor.ByteCountVisitor;
+import org.apache.phoenix.execute.visitor.QueryPlanVisitor;
+import org.apache.phoenix.execute.visitor.RowCountVisitor;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.OrderByExpression;
 import org.apache.phoenix.expression.aggregator.Aggregators;
@@ -90,25 +94,30 @@ public class ClientAggregatePlan extends 
ClientProcessingPlan {
 
 @Override
 public Cost getCost() {
-Long byteCount = null;
-try {
-byteCount = getEstimatedBytesToScan();
-} catch (SQLException e) {
-// ignored.
-}
-
-if (byteCount == null) {
+Double outputBytes = this.accept(new ByteCountVisitor());
+Double inputRows = this.getDelegate().accept(new RowCountVisitor());
+Double rowWidth = this.accept(new AvgRowWidthVisitor());
+if (inputRows == null || outputBytes == null || rowWidth == null) {
 return Cost.UNKNOWN;
 }
+double inputBytes = inputRows * rowWidth;
+double rowsBeforeHaving = RowCountVisitor.aggregate(
+RowCountVisitor.filter(
+inputRows.doubleValue(),
+RowCountVisitor.stripSkipScanFilter(
+context.getScan().getFilter())),
+groupBy);
+double rowsAfterHaving = RowCountVisitor.filter(rowsBeforeHaving, 
having);
+double bytesBeforeHaving = rowWidth * rowsBeforeHaving;
+double bytesAfterHaving = rowWidth * rowsAfterHaving;
 
 int parallelLevel = CostUtil.estimateParallelLevel(
 false, context.getConnection().getQueryServices());
-Cost cost = CostUtil.estimateAggregateCost(byteCount,
-groupBy, clientAggregators.getEstimatedByteSize(), 
parallelLevel);
+Cost cost = CostUtil.estimateAggregateCost(
+inputBytes, bytesBeforeHaving, groupBy, parallelLevel);
 if (!orderBy.getOrderByExpressions().isEmpty()) {
-double outputBytes = CostUtil.estimateAggregateOutputBytes(
-byteCount, groupBy, 
clientAggregators.getEstimatedByteSize());
-Cost orderByCost = CostUtil.estimateOrderByCost(outputBytes, 
parallelLevel);
+Cost orderByCost = CostUtil.estimateOrderByCost(
+bytesAfterHaving, outputBytes, parallelLevel);
 cost = cost.plus(orderByCost);
 }
 return super.getCost().plus(cost);
@@ -210,7 +219,16 @@ public class ClientAggregatePlan extends 
ClientProcessingPlan {
 public GroupBy getGroupBy() {
 return groupBy;
 }
-
+
+@Override
+public  T accept(QueryPlanVisitor visitor) {
+return visitor.visit(this);
+}
+
+public Expression getHaving() {
+return having;
+}
+
 private static class ClientGroupedAggregatingResultIterator extends 
BaseGroupedAggregatingResultIterator {
 private final List groupByExpressions;
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/c7302511/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
index ac43919..75ba8f2 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
@@ -85,4 +85,8 @@ public abstract class ClientProcessingPlan extends 
DelegateQueryPlan {
 public FilterableStatement getStatement() {
 return statement;
 }
+
+public Expression getWhere() {
+return where;
+}
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/c7302511/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientScanPlan.java

[2/2] phoenix git commit: PHOENIX-1556 Base hash versus sort merge join decision on cost

2018-02-12 Thread maryannxue
PHOENIX-1556 Base hash versus sort merge join decision on cost


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

Branch: refs/heads/4.x-HBase-1.2
Commit: c73025115fd007240b705b5ce25fbcb37b999ec9
Parents: ff4ad20
Author: maryannxue <maryann@gmail.com>
Authored: Mon Feb 12 14:23:52 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Mon Feb 12 14:23:52 2018 -0800

--
 .../phoenix/end2end/CostBasedDecisionIT.java| 420 -
 .../apache/phoenix/compile/JoinCompiler.java|  43 ++
 .../phoenix/compile/ListJarsQueryPlan.java  |   8 +-
 .../apache/phoenix/compile/QueryCompiler.java   | 449 ++-
 .../org/apache/phoenix/compile/QueryPlan.java   |   2 +
 .../apache/phoenix/compile/TraceQueryPlan.java  |   6 +
 .../apache/phoenix/execute/AggregatePlan.java   |  41 +-
 .../phoenix/execute/ClientAggregatePlan.java|  46 +-
 .../phoenix/execute/ClientProcessingPlan.java   |   4 +
 .../apache/phoenix/execute/ClientScanPlan.java  |  22 +-
 .../apache/phoenix/execute/CorrelatePlan.java   |  26 +-
 .../apache/phoenix/execute/CursorFetchPlan.java |   6 +
 .../apache/phoenix/execute/HashJoinPlan.java| 128 --
 .../execute/LiteralResultIterationPlan.java |   6 +
 .../org/apache/phoenix/execute/ScanPlan.java|  14 +-
 .../phoenix/execute/SortMergeJoinPlan.java  |  20 +-
 .../phoenix/execute/TupleProjectionPlan.java|   6 +
 .../org/apache/phoenix/execute/UnionPlan.java   |  12 +-
 .../apache/phoenix/execute/UnnestArrayPlan.java |   6 +
 .../execute/visitor/AvgRowWidthVisitor.java | 205 +
 .../execute/visitor/ByteCountVisitor.java   | 125 ++
 .../execute/visitor/QueryPlanVisitor.java   |  46 ++
 .../execute/visitor/RowCountVisitor.java| 335 ++
 .../apache/phoenix/jdbc/PhoenixStatement.java   |   6 +
 .../java/org/apache/phoenix/util/CostUtil.java  |  61 +--
 .../query/ParallelIteratorsSplitTest.java   |   6 +
 26 files changed, 1612 insertions(+), 437 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/c7302511/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
index a3584ce..493855a 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
@@ -32,12 +32,16 @@ import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.QueryUtil;
 import org.apache.phoenix.util.ReadOnlyProps;
+
 import org.junit.BeforeClass;
 import org.junit.Test;
 
 import com.google.common.collect.Maps;
 
 public class CostBasedDecisionIT extends BaseUniqueNamesOwnClusterIT {
+private final String testTable500;
+private final String testTable990;
+private final String testTable1000;
 
 @BeforeClass
 public static void doSetup() throws Exception {
@@ -46,9 +50,16 @@ public class CostBasedDecisionIT extends 
BaseUniqueNamesOwnClusterIT {
 props.put(QueryServices.STATS_UPDATE_FREQ_MS_ATTRIB, Long.toString(5));
 props.put(QueryServices.USE_STATS_FOR_PARALLELIZATION, 
Boolean.toString(true));
 props.put(QueryServices.COST_BASED_OPTIMIZER_ENABLED, 
Boolean.toString(true));
+props.put(QueryServices.MAX_SERVER_CACHE_SIZE_ATTRIB, 
Long.toString(15));
 setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
 }
 
+public CostBasedDecisionIT() throws Exception {
+testTable500 = initTestTableValues(500);
+testTable990 = initTestTableValues(990);
+testTable1000 = initTestTableValues(1000);
+}
+
 @Test
 public void testCostOverridesStaticPlanOrdering1() throws Exception {
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
@@ -64,10 +75,7 @@ public class CostBasedDecisionIT extends 
BaseUniqueNamesOwnClusterIT {
 
 String query = "SELECT rowkey, c1, c2 FROM " + tableName + " where 
c1 LIKE 'X0%' ORDER BY rowkey";
 // Use the data table plan that opts out order-by when stats are 
not available.
-ResultSet rs = conn.createStatement().executeQuery("explain " + 
query);
-String plan = QueryUtil.getExplainPlan(rs);
-assertTrue("Expected 'FULL SCAN' in the plan:\n" + plan 

[1/2] phoenix git commit: PHOENIX-1556 Base hash versus sort merge join decision on cost

2018-02-12 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.3 74b2dcc53 -> ab9070910


http://git-wip-us.apache.org/repos/asf/phoenix/blob/ab907091/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
index a15ab35..21cbc2d 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
@@ -35,6 +35,10 @@ import org.apache.phoenix.compile.QueryPlan;
 import org.apache.phoenix.compile.RowProjector;
 import org.apache.phoenix.compile.StatementContext;
 import org.apache.phoenix.coprocessor.BaseScannerRegionObserver;
+import org.apache.phoenix.execute.visitor.AvgRowWidthVisitor;
+import org.apache.phoenix.execute.visitor.ByteCountVisitor;
+import org.apache.phoenix.execute.visitor.QueryPlanVisitor;
+import org.apache.phoenix.execute.visitor.RowCountVisitor;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.OrderByExpression;
 import org.apache.phoenix.expression.aggregator.Aggregators;
@@ -90,25 +94,30 @@ public class ClientAggregatePlan extends 
ClientProcessingPlan {
 
 @Override
 public Cost getCost() {
-Long byteCount = null;
-try {
-byteCount = getEstimatedBytesToScan();
-} catch (SQLException e) {
-// ignored.
-}
-
-if (byteCount == null) {
+Double outputBytes = this.accept(new ByteCountVisitor());
+Double inputRows = this.getDelegate().accept(new RowCountVisitor());
+Double rowWidth = this.accept(new AvgRowWidthVisitor());
+if (inputRows == null || outputBytes == null || rowWidth == null) {
 return Cost.UNKNOWN;
 }
+double inputBytes = inputRows * rowWidth;
+double rowsBeforeHaving = RowCountVisitor.aggregate(
+RowCountVisitor.filter(
+inputRows.doubleValue(),
+RowCountVisitor.stripSkipScanFilter(
+context.getScan().getFilter())),
+groupBy);
+double rowsAfterHaving = RowCountVisitor.filter(rowsBeforeHaving, 
having);
+double bytesBeforeHaving = rowWidth * rowsBeforeHaving;
+double bytesAfterHaving = rowWidth * rowsAfterHaving;
 
 int parallelLevel = CostUtil.estimateParallelLevel(
 false, context.getConnection().getQueryServices());
-Cost cost = CostUtil.estimateAggregateCost(byteCount,
-groupBy, clientAggregators.getEstimatedByteSize(), 
parallelLevel);
+Cost cost = CostUtil.estimateAggregateCost(
+inputBytes, bytesBeforeHaving, groupBy, parallelLevel);
 if (!orderBy.getOrderByExpressions().isEmpty()) {
-double outputBytes = CostUtil.estimateAggregateOutputBytes(
-byteCount, groupBy, 
clientAggregators.getEstimatedByteSize());
-Cost orderByCost = CostUtil.estimateOrderByCost(outputBytes, 
parallelLevel);
+Cost orderByCost = CostUtil.estimateOrderByCost(
+bytesAfterHaving, outputBytes, parallelLevel);
 cost = cost.plus(orderByCost);
 }
 return super.getCost().plus(cost);
@@ -210,7 +219,16 @@ public class ClientAggregatePlan extends 
ClientProcessingPlan {
 public GroupBy getGroupBy() {
 return groupBy;
 }
-
+
+@Override
+public  T accept(QueryPlanVisitor visitor) {
+return visitor.visit(this);
+}
+
+public Expression getHaving() {
+return having;
+}
+
 private static class ClientGroupedAggregatingResultIterator extends 
BaseGroupedAggregatingResultIterator {
 private final List groupByExpressions;
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/ab907091/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
index ac43919..75ba8f2 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
@@ -85,4 +85,8 @@ public abstract class ClientProcessingPlan extends 
DelegateQueryPlan {
 public FilterableStatement getStatement() {
 return statement;
 }
+
+public Expression getWhere() {
+return where;
+}
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/ab907091/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientScanPlan.java

[2/2] phoenix git commit: PHOENIX-1556 Base hash versus sort merge join decision on cost

2018-02-12 Thread maryannxue
PHOENIX-1556 Base hash versus sort merge join decision on cost


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

Branch: refs/heads/4.x-HBase-1.3
Commit: ab90709104f775cf8fbf7e23079e50bbd8f570e9
Parents: 74b2dcc
Author: maryannxue <maryann@gmail.com>
Authored: Mon Feb 12 14:22:54 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Mon Feb 12 14:22:54 2018 -0800

--
 .../phoenix/end2end/CostBasedDecisionIT.java| 420 -
 .../apache/phoenix/compile/JoinCompiler.java|  43 ++
 .../phoenix/compile/ListJarsQueryPlan.java  |   8 +-
 .../apache/phoenix/compile/QueryCompiler.java   | 449 ++-
 .../org/apache/phoenix/compile/QueryPlan.java   |   2 +
 .../apache/phoenix/compile/TraceQueryPlan.java  |   6 +
 .../apache/phoenix/execute/AggregatePlan.java   |  41 +-
 .../phoenix/execute/ClientAggregatePlan.java|  46 +-
 .../phoenix/execute/ClientProcessingPlan.java   |   4 +
 .../apache/phoenix/execute/ClientScanPlan.java  |  22 +-
 .../apache/phoenix/execute/CorrelatePlan.java   |  26 +-
 .../apache/phoenix/execute/CursorFetchPlan.java |   6 +
 .../apache/phoenix/execute/HashJoinPlan.java| 128 --
 .../execute/LiteralResultIterationPlan.java |   6 +
 .../org/apache/phoenix/execute/ScanPlan.java|  14 +-
 .../phoenix/execute/SortMergeJoinPlan.java  |  20 +-
 .../phoenix/execute/TupleProjectionPlan.java|   6 +
 .../org/apache/phoenix/execute/UnionPlan.java   |  12 +-
 .../apache/phoenix/execute/UnnestArrayPlan.java |   6 +
 .../execute/visitor/AvgRowWidthVisitor.java | 205 +
 .../execute/visitor/ByteCountVisitor.java   | 125 ++
 .../execute/visitor/QueryPlanVisitor.java   |  46 ++
 .../execute/visitor/RowCountVisitor.java| 335 ++
 .../apache/phoenix/jdbc/PhoenixStatement.java   |   6 +
 .../java/org/apache/phoenix/util/CostUtil.java  |  61 +--
 .../query/ParallelIteratorsSplitTest.java   |   6 +
 26 files changed, 1612 insertions(+), 437 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/ab907091/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
index a3584ce..493855a 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
@@ -32,12 +32,16 @@ import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.QueryUtil;
 import org.apache.phoenix.util.ReadOnlyProps;
+
 import org.junit.BeforeClass;
 import org.junit.Test;
 
 import com.google.common.collect.Maps;
 
 public class CostBasedDecisionIT extends BaseUniqueNamesOwnClusterIT {
+private final String testTable500;
+private final String testTable990;
+private final String testTable1000;
 
 @BeforeClass
 public static void doSetup() throws Exception {
@@ -46,9 +50,16 @@ public class CostBasedDecisionIT extends 
BaseUniqueNamesOwnClusterIT {
 props.put(QueryServices.STATS_UPDATE_FREQ_MS_ATTRIB, Long.toString(5));
 props.put(QueryServices.USE_STATS_FOR_PARALLELIZATION, 
Boolean.toString(true));
 props.put(QueryServices.COST_BASED_OPTIMIZER_ENABLED, 
Boolean.toString(true));
+props.put(QueryServices.MAX_SERVER_CACHE_SIZE_ATTRIB, 
Long.toString(15));
 setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
 }
 
+public CostBasedDecisionIT() throws Exception {
+testTable500 = initTestTableValues(500);
+testTable990 = initTestTableValues(990);
+testTable1000 = initTestTableValues(1000);
+}
+
 @Test
 public void testCostOverridesStaticPlanOrdering1() throws Exception {
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
@@ -64,10 +75,7 @@ public class CostBasedDecisionIT extends 
BaseUniqueNamesOwnClusterIT {
 
 String query = "SELECT rowkey, c1, c2 FROM " + tableName + " where 
c1 LIKE 'X0%' ORDER BY rowkey";
 // Use the data table plan that opts out order-by when stats are 
not available.
-ResultSet rs = conn.createStatement().executeQuery("explain " + 
query);
-String plan = QueryUtil.getExplainPlan(rs);
-assertTrue("Expected 'FULL SCAN' in the plan:\n" + plan 

[1/2] phoenix git commit: PHOENIX-1556 Base hash versus sort merge join decision on cost

2018-02-12 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/master a6bf7350d -> 9461d0d6a


http://git-wip-us.apache.org/repos/asf/phoenix/blob/9461d0d6/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
index a15ab35..21cbc2d 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientAggregatePlan.java
@@ -35,6 +35,10 @@ import org.apache.phoenix.compile.QueryPlan;
 import org.apache.phoenix.compile.RowProjector;
 import org.apache.phoenix.compile.StatementContext;
 import org.apache.phoenix.coprocessor.BaseScannerRegionObserver;
+import org.apache.phoenix.execute.visitor.AvgRowWidthVisitor;
+import org.apache.phoenix.execute.visitor.ByteCountVisitor;
+import org.apache.phoenix.execute.visitor.QueryPlanVisitor;
+import org.apache.phoenix.execute.visitor.RowCountVisitor;
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.OrderByExpression;
 import org.apache.phoenix.expression.aggregator.Aggregators;
@@ -90,25 +94,30 @@ public class ClientAggregatePlan extends 
ClientProcessingPlan {
 
 @Override
 public Cost getCost() {
-Long byteCount = null;
-try {
-byteCount = getEstimatedBytesToScan();
-} catch (SQLException e) {
-// ignored.
-}
-
-if (byteCount == null) {
+Double outputBytes = this.accept(new ByteCountVisitor());
+Double inputRows = this.getDelegate().accept(new RowCountVisitor());
+Double rowWidth = this.accept(new AvgRowWidthVisitor());
+if (inputRows == null || outputBytes == null || rowWidth == null) {
 return Cost.UNKNOWN;
 }
+double inputBytes = inputRows * rowWidth;
+double rowsBeforeHaving = RowCountVisitor.aggregate(
+RowCountVisitor.filter(
+inputRows.doubleValue(),
+RowCountVisitor.stripSkipScanFilter(
+context.getScan().getFilter())),
+groupBy);
+double rowsAfterHaving = RowCountVisitor.filter(rowsBeforeHaving, 
having);
+double bytesBeforeHaving = rowWidth * rowsBeforeHaving;
+double bytesAfterHaving = rowWidth * rowsAfterHaving;
 
 int parallelLevel = CostUtil.estimateParallelLevel(
 false, context.getConnection().getQueryServices());
-Cost cost = CostUtil.estimateAggregateCost(byteCount,
-groupBy, clientAggregators.getEstimatedByteSize(), 
parallelLevel);
+Cost cost = CostUtil.estimateAggregateCost(
+inputBytes, bytesBeforeHaving, groupBy, parallelLevel);
 if (!orderBy.getOrderByExpressions().isEmpty()) {
-double outputBytes = CostUtil.estimateAggregateOutputBytes(
-byteCount, groupBy, 
clientAggregators.getEstimatedByteSize());
-Cost orderByCost = CostUtil.estimateOrderByCost(outputBytes, 
parallelLevel);
+Cost orderByCost = CostUtil.estimateOrderByCost(
+bytesAfterHaving, outputBytes, parallelLevel);
 cost = cost.plus(orderByCost);
 }
 return super.getCost().plus(cost);
@@ -210,7 +219,16 @@ public class ClientAggregatePlan extends 
ClientProcessingPlan {
 public GroupBy getGroupBy() {
 return groupBy;
 }
-
+
+@Override
+public  T accept(QueryPlanVisitor visitor) {
+return visitor.visit(this);
+}
+
+public Expression getHaving() {
+return having;
+}
+
 private static class ClientGroupedAggregatingResultIterator extends 
BaseGroupedAggregatingResultIterator {
 private final List groupByExpressions;
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9461d0d6/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
index ac43919..75ba8f2 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientProcessingPlan.java
@@ -85,4 +85,8 @@ public abstract class ClientProcessingPlan extends 
DelegateQueryPlan {
 public FilterableStatement getStatement() {
 return statement;
 }
+
+public Expression getWhere() {
+return where;
+}
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/9461d0d6/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientScanPlan.java

[2/2] phoenix git commit: PHOENIX-1556 Base hash versus sort merge join decision on cost

2018-02-12 Thread maryannxue
PHOENIX-1556 Base hash versus sort merge join decision on cost


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

Branch: refs/heads/master
Commit: 9461d0d6a299bb3cbcf53905d7e9b73895a99299
Parents: a6bf735
Author: maryannxue <maryann@gmail.com>
Authored: Mon Feb 12 14:07:30 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Mon Feb 12 14:07:30 2018 -0800

--
 .../phoenix/end2end/CostBasedDecisionIT.java| 420 -
 .../apache/phoenix/compile/JoinCompiler.java|  43 ++
 .../phoenix/compile/ListJarsQueryPlan.java  |   8 +-
 .../apache/phoenix/compile/QueryCompiler.java   | 449 ++-
 .../org/apache/phoenix/compile/QueryPlan.java   |   2 +
 .../apache/phoenix/compile/TraceQueryPlan.java  |   6 +
 .../apache/phoenix/execute/AggregatePlan.java   |  41 +-
 .../phoenix/execute/ClientAggregatePlan.java|  46 +-
 .../phoenix/execute/ClientProcessingPlan.java   |   4 +
 .../apache/phoenix/execute/ClientScanPlan.java  |  22 +-
 .../apache/phoenix/execute/CorrelatePlan.java   |  26 +-
 .../apache/phoenix/execute/CursorFetchPlan.java |   6 +
 .../apache/phoenix/execute/HashJoinPlan.java| 128 --
 .../execute/LiteralResultIterationPlan.java |   6 +
 .../org/apache/phoenix/execute/ScanPlan.java|  14 +-
 .../phoenix/execute/SortMergeJoinPlan.java  |  20 +-
 .../phoenix/execute/TupleProjectionPlan.java|   6 +
 .../org/apache/phoenix/execute/UnionPlan.java   |  12 +-
 .../apache/phoenix/execute/UnnestArrayPlan.java |   6 +
 .../execute/visitor/AvgRowWidthVisitor.java | 205 +
 .../execute/visitor/ByteCountVisitor.java   | 125 ++
 .../execute/visitor/QueryPlanVisitor.java   |  46 ++
 .../execute/visitor/RowCountVisitor.java| 335 ++
 .../apache/phoenix/jdbc/PhoenixStatement.java   |   6 +
 .../java/org/apache/phoenix/util/CostUtil.java  |  61 +--
 .../query/ParallelIteratorsSplitTest.java   |   6 +
 26 files changed, 1612 insertions(+), 437 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/9461d0d6/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
index a3584ce..493855a 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
@@ -32,12 +32,16 @@ import org.apache.phoenix.query.QueryServices;
 import org.apache.phoenix.util.PropertiesUtil;
 import org.apache.phoenix.util.QueryUtil;
 import org.apache.phoenix.util.ReadOnlyProps;
+
 import org.junit.BeforeClass;
 import org.junit.Test;
 
 import com.google.common.collect.Maps;
 
 public class CostBasedDecisionIT extends BaseUniqueNamesOwnClusterIT {
+private final String testTable500;
+private final String testTable990;
+private final String testTable1000;
 
 @BeforeClass
 public static void doSetup() throws Exception {
@@ -46,9 +50,16 @@ public class CostBasedDecisionIT extends 
BaseUniqueNamesOwnClusterIT {
 props.put(QueryServices.STATS_UPDATE_FREQ_MS_ATTRIB, Long.toString(5));
 props.put(QueryServices.USE_STATS_FOR_PARALLELIZATION, 
Boolean.toString(true));
 props.put(QueryServices.COST_BASED_OPTIMIZER_ENABLED, 
Boolean.toString(true));
+props.put(QueryServices.MAX_SERVER_CACHE_SIZE_ATTRIB, 
Long.toString(15));
 setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator()));
 }
 
+public CostBasedDecisionIT() throws Exception {
+testTable500 = initTestTableValues(500);
+testTable990 = initTestTableValues(990);
+testTable1000 = initTestTableValues(1000);
+}
+
 @Test
 public void testCostOverridesStaticPlanOrdering1() throws Exception {
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
@@ -64,10 +75,7 @@ public class CostBasedDecisionIT extends 
BaseUniqueNamesOwnClusterIT {
 
 String query = "SELECT rowkey, c1, c2 FROM " + tableName + " where 
c1 LIKE 'X0%' ORDER BY rowkey";
 // Use the data table plan that opts out order-by when stats are 
not available.
-ResultSet rs = conn.createStatement().executeQuery("explain " + 
query);
-String plan = QueryUtil.getExplainPlan(rs);
-assertTrue("Expected 'FULL SCAN' in the plan:\n" + plan + ".",
-   

phoenix git commit: PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for subqueries.

2018-02-08 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-cdh5.11.2 6b693e93f -> ce7fae412


PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for 
subqueries.


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

Branch: refs/heads/4.x-cdh5.11.2
Commit: ce7fae41268dc464e1dd236fb83d557c1d107e7a
Parents: 6b693e9
Author: maryannxue <maryann@gmail.com>
Authored: Thu Feb 8 12:52:59 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Thu Feb 8 12:52:59 2018 -0800

--
 .../apache/phoenix/end2end/join/SubqueryIT.java | 41 
 .../apache/phoenix/compile/UpsertCompiler.java  |  3 +-
 .../org/apache/phoenix/parse/ParseNode.java | 26 -
 3 files changed, 68 insertions(+), 2 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/ce7fae41/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
index 604db63..1da98d2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
@@ -744,6 +744,47 @@ public class SubqueryIT extends BaseJoinIT {
 }
 
 @Test
+public void testNoncorrelatedSubqueryWithUpsert() throws Exception {
+String tempTable = generateUniqueName();
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+conn.setAutoCommit(true);
+try {
+conn.createStatement().execute("CREATE TABLE " + tempTable
++ "   (item_id varchar not null primary key, "
++ "name varchar)");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('1', 'a')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('2', 'b')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ALL (SELECT name FROM 
" + tempTable + ")");
+
+String query = "SELECT name FROM " + tempTable + " ORDER BY 
item_id";
+PreparedStatement statement = conn.prepareStatement(query);
+ResultSet rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("b", rs.getString(1));
+assertFalse(rs.next());
+
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ANY (SELECT name FROM 
" + tempTable + ")");
+
+statement = conn.prepareStatement(query);
+rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("x", rs.getString(1));
+assertFalse(rs.next());
+} finally {
+conn.close();
+}
+}
+
+@Test
 public void testSubqueryWithDelete() throws Exception {
 String tempTable = generateUniqueName();
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/ce7fae41/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
index 08133a4..ba202c8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
@@ -533,9 +533,10 @@ public class UpsertCompiler {
 // region space managed by region servers. So we bail out on 
executing on server side.
 // Disable running upsert sel

phoenix git commit: PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for subqueries.

2018-02-08 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 ea57ee008 -> 63fa82e63


PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for 
subqueries.


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

Branch: refs/heads/4.x-HBase-0.98
Commit: 63fa82e6374a03f0d243820b1e135cc88e185381
Parents: ea57ee0
Author: maryannxue <maryann@gmail.com>
Authored: Thu Feb 8 12:51:16 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Thu Feb 8 12:51:16 2018 -0800

--
 .../apache/phoenix/end2end/join/SubqueryIT.java | 41 
 .../apache/phoenix/compile/UpsertCompiler.java  |  3 +-
 .../org/apache/phoenix/parse/ParseNode.java | 26 -
 3 files changed, 68 insertions(+), 2 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/63fa82e6/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
index 604db63..1da98d2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
@@ -744,6 +744,47 @@ public class SubqueryIT extends BaseJoinIT {
 }
 
 @Test
+public void testNoncorrelatedSubqueryWithUpsert() throws Exception {
+String tempTable = generateUniqueName();
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+conn.setAutoCommit(true);
+try {
+conn.createStatement().execute("CREATE TABLE " + tempTable
++ "   (item_id varchar not null primary key, "
++ "name varchar)");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('1', 'a')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('2', 'b')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ALL (SELECT name FROM 
" + tempTable + ")");
+
+String query = "SELECT name FROM " + tempTable + " ORDER BY 
item_id";
+PreparedStatement statement = conn.prepareStatement(query);
+ResultSet rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("b", rs.getString(1));
+assertFalse(rs.next());
+
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ANY (SELECT name FROM 
" + tempTable + ")");
+
+statement = conn.prepareStatement(query);
+rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("x", rs.getString(1));
+assertFalse(rs.next());
+} finally {
+conn.close();
+}
+}
+
+@Test
 public void testSubqueryWithDelete() throws Exception {
 String tempTable = generateUniqueName();
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/63fa82e6/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
index fcac335..ea32b9f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
@@ -532,9 +532,10 @@ public class UpsertCompiler {
 // region space managed by region servers. So we bail out on 
executing on server side.
 // Disable running upsert sel

phoenix git commit: PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for subqueries.

2018-02-08 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.1 260278532 -> 587f78de2


PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for 
subqueries.


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

Branch: refs/heads/4.x-HBase-1.1
Commit: 587f78de2f0c5b204523ed5116301566bb6559c9
Parents: 2602785
Author: maryannxue <maryann@gmail.com>
Authored: Thu Feb 8 12:50:31 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Thu Feb 8 12:50:31 2018 -0800

--
 .../apache/phoenix/end2end/join/SubqueryIT.java | 41 
 .../apache/phoenix/compile/UpsertCompiler.java  |  3 +-
 .../org/apache/phoenix/parse/ParseNode.java | 26 -
 3 files changed, 68 insertions(+), 2 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/587f78de/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
index 604db63..1da98d2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
@@ -744,6 +744,47 @@ public class SubqueryIT extends BaseJoinIT {
 }
 
 @Test
+public void testNoncorrelatedSubqueryWithUpsert() throws Exception {
+String tempTable = generateUniqueName();
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+conn.setAutoCommit(true);
+try {
+conn.createStatement().execute("CREATE TABLE " + tempTable
++ "   (item_id varchar not null primary key, "
++ "name varchar)");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('1', 'a')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('2', 'b')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ALL (SELECT name FROM 
" + tempTable + ")");
+
+String query = "SELECT name FROM " + tempTable + " ORDER BY 
item_id";
+PreparedStatement statement = conn.prepareStatement(query);
+ResultSet rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("b", rs.getString(1));
+assertFalse(rs.next());
+
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ANY (SELECT name FROM 
" + tempTable + ")");
+
+statement = conn.prepareStatement(query);
+rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("x", rs.getString(1));
+assertFalse(rs.next());
+} finally {
+conn.close();
+}
+}
+
+@Test
 public void testSubqueryWithDelete() throws Exception {
 String tempTable = generateUniqueName();
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/587f78de/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
index 08133a4..ba202c8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
@@ -533,9 +533,10 @@ public class UpsertCompiler {
 // region space managed by region servers. So we bail out on 
executing on server side.
 // Disable running upsert sel

phoenix git commit: PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for subqueries.

2018-02-08 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.2 a642a5577 -> 48d1df3dd


PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for 
subqueries.


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

Branch: refs/heads/4.x-HBase-1.2
Commit: 48d1df3dd6b7316ed56b46d5a0471525dc8709e5
Parents: a642a55
Author: maryannxue <maryann@gmail.com>
Authored: Thu Feb 8 12:50:07 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Thu Feb 8 12:50:07 2018 -0800

--
 .../apache/phoenix/end2end/join/SubqueryIT.java | 41 
 .../apache/phoenix/compile/UpsertCompiler.java  |  3 +-
 .../org/apache/phoenix/parse/ParseNode.java | 26 -
 3 files changed, 68 insertions(+), 2 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/48d1df3d/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
index 604db63..1da98d2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
@@ -744,6 +744,47 @@ public class SubqueryIT extends BaseJoinIT {
 }
 
 @Test
+public void testNoncorrelatedSubqueryWithUpsert() throws Exception {
+String tempTable = generateUniqueName();
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+conn.setAutoCommit(true);
+try {
+conn.createStatement().execute("CREATE TABLE " + tempTable
++ "   (item_id varchar not null primary key, "
++ "name varchar)");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('1', 'a')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('2', 'b')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ALL (SELECT name FROM 
" + tempTable + ")");
+
+String query = "SELECT name FROM " + tempTable + " ORDER BY 
item_id";
+PreparedStatement statement = conn.prepareStatement(query);
+ResultSet rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("b", rs.getString(1));
+assertFalse(rs.next());
+
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ANY (SELECT name FROM 
" + tempTable + ")");
+
+statement = conn.prepareStatement(query);
+rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("x", rs.getString(1));
+assertFalse(rs.next());
+} finally {
+conn.close();
+}
+}
+
+@Test
 public void testSubqueryWithDelete() throws Exception {
 String tempTable = generateUniqueName();
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/48d1df3d/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
index 08133a4..ba202c8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
@@ -533,9 +533,10 @@ public class UpsertCompiler {
 // region space managed by region servers. So we bail out on 
executing on server side.
 // Disable running upsert sel

phoenix git commit: PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for subqueries.

2018-02-08 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.3 507f2b8ee -> 7bf3a5753


PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for 
subqueries.


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

Branch: refs/heads/4.x-HBase-1.3
Commit: 7bf3a575339ff0003ddf1cce48b7484bc352337f
Parents: 507f2b8
Author: maryannxue <maryann@gmail.com>
Authored: Thu Feb 8 12:49:35 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Thu Feb 8 12:49:35 2018 -0800

--
 .../apache/phoenix/end2end/join/SubqueryIT.java | 41 
 .../apache/phoenix/compile/UpsertCompiler.java  |  3 +-
 .../org/apache/phoenix/parse/ParseNode.java | 26 -
 3 files changed, 68 insertions(+), 2 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/7bf3a575/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
index 604db63..1da98d2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
@@ -744,6 +744,47 @@ public class SubqueryIT extends BaseJoinIT {
 }
 
 @Test
+public void testNoncorrelatedSubqueryWithUpsert() throws Exception {
+String tempTable = generateUniqueName();
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+conn.setAutoCommit(true);
+try {
+conn.createStatement().execute("CREATE TABLE " + tempTable
++ "   (item_id varchar not null primary key, "
++ "name varchar)");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('1', 'a')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('2', 'b')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ALL (SELECT name FROM 
" + tempTable + ")");
+
+String query = "SELECT name FROM " + tempTable + " ORDER BY 
item_id";
+PreparedStatement statement = conn.prepareStatement(query);
+ResultSet rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("b", rs.getString(1));
+assertFalse(rs.next());
+
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ANY (SELECT name FROM 
" + tempTable + ")");
+
+statement = conn.prepareStatement(query);
+rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("x", rs.getString(1));
+assertFalse(rs.next());
+} finally {
+conn.close();
+}
+}
+
+@Test
 public void testSubqueryWithDelete() throws Exception {
 String tempTable = generateUniqueName();
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/7bf3a575/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
index 08133a4..ba202c8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
@@ -533,9 +533,10 @@ public class UpsertCompiler {
 // region space managed by region servers. So we bail out on 
executing on server side.
 // Disable running upsert sel

phoenix git commit: PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for subqueries.

2018-02-08 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/5.x-HBase-2.0 d1ad1f585 -> a7bb5c44c


PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for 
subqueries.


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

Branch: refs/heads/5.x-HBase-2.0
Commit: a7bb5c44c6b6b8ac5ec5c26555602280bf0680df
Parents: d1ad1f5
Author: maryannxue <maryann@gmail.com>
Authored: Thu Feb 8 12:40:29 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Thu Feb 8 12:40:29 2018 -0800

--
 .../apache/phoenix/end2end/join/SubqueryIT.java | 41 
 .../apache/phoenix/compile/UpsertCompiler.java  |  3 +-
 .../org/apache/phoenix/parse/ParseNode.java | 26 -
 3 files changed, 68 insertions(+), 2 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/a7bb5c44/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
index 604db63..1da98d2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
@@ -744,6 +744,47 @@ public class SubqueryIT extends BaseJoinIT {
 }
 
 @Test
+public void testNoncorrelatedSubqueryWithUpsert() throws Exception {
+String tempTable = generateUniqueName();
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+conn.setAutoCommit(true);
+try {
+conn.createStatement().execute("CREATE TABLE " + tempTable
++ "   (item_id varchar not null primary key, "
++ "name varchar)");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('1', 'a')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('2', 'b')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ALL (SELECT name FROM 
" + tempTable + ")");
+
+String query = "SELECT name FROM " + tempTable + " ORDER BY 
item_id";
+PreparedStatement statement = conn.prepareStatement(query);
+ResultSet rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("b", rs.getString(1));
+assertFalse(rs.next());
+
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ANY (SELECT name FROM 
" + tempTable + ")");
+
+statement = conn.prepareStatement(query);
+rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("x", rs.getString(1));
+assertFalse(rs.next());
+} finally {
+conn.close();
+}
+}
+
+@Test
 public void testSubqueryWithDelete() throws Exception {
 String tempTable = generateUniqueName();
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/a7bb5c44/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
index a0c0971..af9d183 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
@@ -530,9 +530,10 @@ public class UpsertCompiler {
 // region space managed by region servers. So we bail out on 
executing on server side.
 // Disable running upsert sel

phoenix git commit: PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for subqueries.

2018-02-08 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/master ba8bcefc9 -> 82bbfdb1d


PHOENIX-4586 UPSERT SELECT doesn't take in account comparison operators for 
subqueries.


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

Branch: refs/heads/master
Commit: 82bbfdb1d547664513274b2450fff2104bd6b234
Parents: ba8bcef
Author: maryannxue <maryann@gmail.com>
Authored: Thu Feb 8 12:38:52 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Thu Feb 8 12:38:52 2018 -0800

--
 .../apache/phoenix/end2end/join/SubqueryIT.java | 41 
 .../apache/phoenix/compile/UpsertCompiler.java  |  3 +-
 .../org/apache/phoenix/parse/ParseNode.java | 26 -
 3 files changed, 68 insertions(+), 2 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/82bbfdb1/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
index 604db63..1da98d2 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/SubqueryIT.java
@@ -744,6 +744,47 @@ public class SubqueryIT extends BaseJoinIT {
 }
 
 @Test
+public void testNoncorrelatedSubqueryWithUpsert() throws Exception {
+String tempTable = generateUniqueName();
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+conn.setAutoCommit(true);
+try {
+conn.createStatement().execute("CREATE TABLE " + tempTable
++ "   (item_id varchar not null primary key, "
++ "name varchar)");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('1', 'a')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + " 
VALUES('2', 'b')");
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ALL (SELECT name FROM 
" + tempTable + ")");
+
+String query = "SELECT name FROM " + tempTable + " ORDER BY 
item_id";
+PreparedStatement statement = conn.prepareStatement(query);
+ResultSet rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("b", rs.getString(1));
+assertFalse(rs.next());
+
+conn.createStatement().execute("UPSERT INTO " + tempTable + 
"(item_id, name)"
++ "   SELECT item_id, 'x' FROM " + tempTable
++ "   WHERE item_id < 'z' AND name > ANY (SELECT name FROM 
" + tempTable + ")");
+
+statement = conn.prepareStatement(query);
+rs = statement.executeQuery();
+assertTrue(rs.next());
+assertEquals("a", rs.getString(1));
+assertTrue(rs.next());
+assertEquals("x", rs.getString(1));
+assertFalse(rs.next());
+} finally {
+conn.close();
+}
+}
+
+@Test
 public void testSubqueryWithDelete() throws Exception {
 String tempTable = generateUniqueName();
 Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/82bbfdb1/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
index 08133a4..ba202c8 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
@@ -533,9 +533,10 @@ public class UpsertCompiler {
 // region space managed by region servers. So we bail out on 
executing on server side.
 // Disable running upsert select on server side i

phoenix git commit: PHOENIX-4508 Order-by not optimized in sort-merge-join on salted tables

2018-01-08 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.13-HBase-1.3 3f627f005 -> 8fd577f3f


PHOENIX-4508 Order-by not optimized in sort-merge-join on salted tables


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

Branch: refs/heads/4.13-HBase-1.3
Commit: 8fd577f3fe3ea6d9f678e29df16ffd1f6ae6744c
Parents: 3f627f0
Author: maryannxue <maryann@gmail.com>
Authored: Mon Jan 8 11:30:07 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Mon Jan 8 11:30:07 2018 -0800

--
 .../phoenix/end2end/SortMergeJoinMoreIT.java| 108 +++
 .../compile/TupleProjectionCompiler.java|   7 +-
 2 files changed, 111 insertions(+), 4 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/8fd577f3/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
index e61332b..a132728 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
@@ -634,4 +634,112 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 }
 }
 }
+
+@Test
+public void testBug4508() throws Exception {
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+props.setProperty("TenantId", "010");
+Connection conn010 = DriverManager.getConnection(getUrl(), props);
+try {
+// Salted tables
+String peopleTable = generateUniqueName();
+String myTable = generateUniqueName();
+conn.createStatement().execute("CREATE TABLE " + peopleTable + " 
(\n" +
+"PERSON_ID VARCHAR NOT NULL,\n" +
+"NAME VARCHAR\n" +
+"CONSTRAINT PK_TEST_PEOPLE PRIMARY KEY (PERSON_ID)) 
SALT_BUCKETS = 3");
+conn.createStatement().execute("CREATE TABLE " + myTable + " (\n" +
+"LOCALID VARCHAR NOT NULL,\n" +
+"DSID VARCHAR(255) NOT NULL, \n" +
+"EID CHAR(40),\n" +
+"HAS_CANDIDATES BOOLEAN\n" +
+"CONSTRAINT PK_MYTABLE PRIMARY KEY (LOCALID, DSID)) 
SALT_BUCKETS = 3");
+verifyQueryPlanAndResultForBug4508(conn, peopleTable, myTable);
+
+// Salted multi-tenant tables
+String peopleTable2 = generateUniqueName();
+String myTable2 = generateUniqueName();
+conn.createStatement().execute("CREATE TABLE " + peopleTable2 + " 
(\n" +
+"TENANT_ID VARCHAR NOT NULL,\n" +
+"PERSON_ID VARCHAR NOT NULL,\n" +
+"NAME VARCHAR\n" +
+"CONSTRAINT PK_TEST_PEOPLE PRIMARY KEY (TENANT_ID, 
PERSON_ID))\n" +
+"SALT_BUCKETS = 3, MULTI_TENANT=true");
+conn.createStatement().execute("CREATE TABLE " + myTable2 + " (\n" 
+
+"TENANT_ID VARCHAR NOT NULL,\n" +
+"LOCALID VARCHAR NOT NULL,\n" +
+"DSID VARCHAR(255) NOT NULL, \n" +
+"EID CHAR(40),\n" +
+"HAS_CANDIDATES BOOLEAN\n" +
+"CONSTRAINT PK_MYTABLE PRIMARY KEY (TENANT_ID, LOCALID, 
DSID))\n" +
+"SALT_BUCKETS = 3, MULTI_TENANT=true");
+verifyQueryPlanAndResultForBug4508(conn010, peopleTable2, 
myTable2);
+} finally {
+conn.close();
+conn010.close();
+}
+}
+
+private static void verifyQueryPlanAndResultForBug4508(
+Connection conn, String peopleTable, String myTable) throws 
Exception {
+PreparedStatement peopleTableUpsertStmt = conn.prepareStatement(
+"UPSERT INTO " + peopleTable + " VALUES(?, ?)");
+peopleTableUpsertStmt.setString(1, "X001");
+peopleTableUpsertStmt.setString(2, "Marcus");
+  

phoenix git commit: PHOENIX-4508 Order-by not optimized in sort-merge-join on salted tables

2018-01-08 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.13-HBase-1.2 05fa73891 -> 75d098f07


PHOENIX-4508 Order-by not optimized in sort-merge-join on salted tables


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

Branch: refs/heads/4.13-HBase-1.2
Commit: 75d098f07055ca862d656a1eee38015750576238
Parents: 05fa738
Author: maryannxue <maryann@gmail.com>
Authored: Mon Jan 8 11:29:37 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Mon Jan 8 11:29:37 2018 -0800

--
 .../phoenix/end2end/SortMergeJoinMoreIT.java| 108 +++
 .../compile/TupleProjectionCompiler.java|   7 +-
 2 files changed, 111 insertions(+), 4 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/75d098f0/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
index e61332b..a132728 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
@@ -634,4 +634,112 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 }
 }
 }
+
+@Test
+public void testBug4508() throws Exception {
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+props.setProperty("TenantId", "010");
+Connection conn010 = DriverManager.getConnection(getUrl(), props);
+try {
+// Salted tables
+String peopleTable = generateUniqueName();
+String myTable = generateUniqueName();
+conn.createStatement().execute("CREATE TABLE " + peopleTable + " 
(\n" +
+"PERSON_ID VARCHAR NOT NULL,\n" +
+"NAME VARCHAR\n" +
+"CONSTRAINT PK_TEST_PEOPLE PRIMARY KEY (PERSON_ID)) 
SALT_BUCKETS = 3");
+conn.createStatement().execute("CREATE TABLE " + myTable + " (\n" +
+"LOCALID VARCHAR NOT NULL,\n" +
+"DSID VARCHAR(255) NOT NULL, \n" +
+"EID CHAR(40),\n" +
+"HAS_CANDIDATES BOOLEAN\n" +
+"CONSTRAINT PK_MYTABLE PRIMARY KEY (LOCALID, DSID)) 
SALT_BUCKETS = 3");
+verifyQueryPlanAndResultForBug4508(conn, peopleTable, myTable);
+
+// Salted multi-tenant tables
+String peopleTable2 = generateUniqueName();
+String myTable2 = generateUniqueName();
+conn.createStatement().execute("CREATE TABLE " + peopleTable2 + " 
(\n" +
+"TENANT_ID VARCHAR NOT NULL,\n" +
+"PERSON_ID VARCHAR NOT NULL,\n" +
+"NAME VARCHAR\n" +
+"CONSTRAINT PK_TEST_PEOPLE PRIMARY KEY (TENANT_ID, 
PERSON_ID))\n" +
+"SALT_BUCKETS = 3, MULTI_TENANT=true");
+conn.createStatement().execute("CREATE TABLE " + myTable2 + " (\n" 
+
+"TENANT_ID VARCHAR NOT NULL,\n" +
+"LOCALID VARCHAR NOT NULL,\n" +
+"DSID VARCHAR(255) NOT NULL, \n" +
+"EID CHAR(40),\n" +
+"HAS_CANDIDATES BOOLEAN\n" +
+"CONSTRAINT PK_MYTABLE PRIMARY KEY (TENANT_ID, LOCALID, 
DSID))\n" +
+"SALT_BUCKETS = 3, MULTI_TENANT=true");
+verifyQueryPlanAndResultForBug4508(conn010, peopleTable2, 
myTable2);
+} finally {
+conn.close();
+conn010.close();
+}
+}
+
+private static void verifyQueryPlanAndResultForBug4508(
+Connection conn, String peopleTable, String myTable) throws 
Exception {
+PreparedStatement peopleTableUpsertStmt = conn.prepareStatement(
+"UPSERT INTO " + peopleTable + " VALUES(?, ?)");
+peopleTableUpsertStmt.setString(1, "X001");
+peopleTableUpsertStmt.setString(2, "Marcus");
+  

phoenix git commit: PHOENIX-4508 Order-by not optimized in sort-merge-join on salted tables

2018-01-08 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.13-HBase-1.1 3a7c4920d -> 2e174be96


PHOENIX-4508 Order-by not optimized in sort-merge-join on salted tables


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

Branch: refs/heads/4.13-HBase-1.1
Commit: 2e174be96a01c66b4e86bff5d9942a00b998e094
Parents: 3a7c492
Author: maryannxue <maryann@gmail.com>
Authored: Mon Jan 8 11:28:17 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Mon Jan 8 11:28:17 2018 -0800

--
 .../phoenix/end2end/SortMergeJoinMoreIT.java| 108 +++
 .../compile/TupleProjectionCompiler.java|   7 +-
 2 files changed, 111 insertions(+), 4 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/2e174be9/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
index e61332b..a132728 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
@@ -634,4 +634,112 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 }
 }
 }
+
+@Test
+public void testBug4508() throws Exception {
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+props.setProperty("TenantId", "010");
+Connection conn010 = DriverManager.getConnection(getUrl(), props);
+try {
+// Salted tables
+String peopleTable = generateUniqueName();
+String myTable = generateUniqueName();
+conn.createStatement().execute("CREATE TABLE " + peopleTable + " 
(\n" +
+"PERSON_ID VARCHAR NOT NULL,\n" +
+"NAME VARCHAR\n" +
+"CONSTRAINT PK_TEST_PEOPLE PRIMARY KEY (PERSON_ID)) 
SALT_BUCKETS = 3");
+conn.createStatement().execute("CREATE TABLE " + myTable + " (\n" +
+"LOCALID VARCHAR NOT NULL,\n" +
+"DSID VARCHAR(255) NOT NULL, \n" +
+"EID CHAR(40),\n" +
+"HAS_CANDIDATES BOOLEAN\n" +
+"CONSTRAINT PK_MYTABLE PRIMARY KEY (LOCALID, DSID)) 
SALT_BUCKETS = 3");
+verifyQueryPlanAndResultForBug4508(conn, peopleTable, myTable);
+
+// Salted multi-tenant tables
+String peopleTable2 = generateUniqueName();
+String myTable2 = generateUniqueName();
+conn.createStatement().execute("CREATE TABLE " + peopleTable2 + " 
(\n" +
+"TENANT_ID VARCHAR NOT NULL,\n" +
+"PERSON_ID VARCHAR NOT NULL,\n" +
+"NAME VARCHAR\n" +
+"CONSTRAINT PK_TEST_PEOPLE PRIMARY KEY (TENANT_ID, 
PERSON_ID))\n" +
+"SALT_BUCKETS = 3, MULTI_TENANT=true");
+conn.createStatement().execute("CREATE TABLE " + myTable2 + " (\n" 
+
+"TENANT_ID VARCHAR NOT NULL,\n" +
+"LOCALID VARCHAR NOT NULL,\n" +
+"DSID VARCHAR(255) NOT NULL, \n" +
+"EID CHAR(40),\n" +
+"HAS_CANDIDATES BOOLEAN\n" +
+"CONSTRAINT PK_MYTABLE PRIMARY KEY (TENANT_ID, LOCALID, 
DSID))\n" +
+"SALT_BUCKETS = 3, MULTI_TENANT=true");
+verifyQueryPlanAndResultForBug4508(conn010, peopleTable2, 
myTable2);
+} finally {
+conn.close();
+conn010.close();
+}
+}
+
+private static void verifyQueryPlanAndResultForBug4508(
+Connection conn, String peopleTable, String myTable) throws 
Exception {
+PreparedStatement peopleTableUpsertStmt = conn.prepareStatement(
+"UPSERT INTO " + peopleTable + " VALUES(?, ?)");
+peopleTableUpsertStmt.setString(1, "X001");
+peopleTableUpsertStmt.setString(2, "Marcus");
+  

phoenix git commit: PHOENIX-4508 Order-by not optimized in sort-merge-join on salted tables

2018-01-08 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.13-HBase-0.98 5fffaca72 -> f87509727


PHOENIX-4508 Order-by not optimized in sort-merge-join on salted tables


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

Branch: refs/heads/4.13-HBase-0.98
Commit: f87509727f1571be2a8964aff4cf2b1e2a627456
Parents: 5fffaca
Author: maryannxue <maryann@gmail.com>
Authored: Mon Jan 8 11:26:58 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Mon Jan 8 11:26:58 2018 -0800

--
 .../phoenix/end2end/SortMergeJoinMoreIT.java| 108 +++
 .../compile/TupleProjectionCompiler.java|   7 +-
 2 files changed, 111 insertions(+), 4 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/f8750972/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
index e61332b..a132728 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
@@ -634,4 +634,112 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 }
 }
 }
+
+@Test
+public void testBug4508() throws Exception {
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+props.setProperty("TenantId", "010");
+Connection conn010 = DriverManager.getConnection(getUrl(), props);
+try {
+// Salted tables
+String peopleTable = generateUniqueName();
+String myTable = generateUniqueName();
+conn.createStatement().execute("CREATE TABLE " + peopleTable + " 
(\n" +
+"PERSON_ID VARCHAR NOT NULL,\n" +
+"NAME VARCHAR\n" +
+"CONSTRAINT PK_TEST_PEOPLE PRIMARY KEY (PERSON_ID)) 
SALT_BUCKETS = 3");
+conn.createStatement().execute("CREATE TABLE " + myTable + " (\n" +
+"LOCALID VARCHAR NOT NULL,\n" +
+"DSID VARCHAR(255) NOT NULL, \n" +
+"EID CHAR(40),\n" +
+"HAS_CANDIDATES BOOLEAN\n" +
+"CONSTRAINT PK_MYTABLE PRIMARY KEY (LOCALID, DSID)) 
SALT_BUCKETS = 3");
+verifyQueryPlanAndResultForBug4508(conn, peopleTable, myTable);
+
+// Salted multi-tenant tables
+String peopleTable2 = generateUniqueName();
+String myTable2 = generateUniqueName();
+conn.createStatement().execute("CREATE TABLE " + peopleTable2 + " 
(\n" +
+"TENANT_ID VARCHAR NOT NULL,\n" +
+"PERSON_ID VARCHAR NOT NULL,\n" +
+"NAME VARCHAR\n" +
+"CONSTRAINT PK_TEST_PEOPLE PRIMARY KEY (TENANT_ID, 
PERSON_ID))\n" +
+"SALT_BUCKETS = 3, MULTI_TENANT=true");
+conn.createStatement().execute("CREATE TABLE " + myTable2 + " (\n" 
+
+"TENANT_ID VARCHAR NOT NULL,\n" +
+"LOCALID VARCHAR NOT NULL,\n" +
+"DSID VARCHAR(255) NOT NULL, \n" +
+"EID CHAR(40),\n" +
+"HAS_CANDIDATES BOOLEAN\n" +
+"CONSTRAINT PK_MYTABLE PRIMARY KEY (TENANT_ID, LOCALID, 
DSID))\n" +
+"SALT_BUCKETS = 3, MULTI_TENANT=true");
+verifyQueryPlanAndResultForBug4508(conn010, peopleTable2, 
myTable2);
+} finally {
+conn.close();
+conn010.close();
+}
+}
+
+private static void verifyQueryPlanAndResultForBug4508(
+Connection conn, String peopleTable, String myTable) throws 
Exception {
+PreparedStatement peopleTableUpsertStmt = conn.prepareStatement(
+"UPSERT INTO " + peopleTable + " VALUES(?, ?)");
+peopleTableUpsertStmt.setString(1, "X001");
+peopleTableUpsertStmt.setString(2, "Marcus");
+  

phoenix git commit: PHOENIX-4508 Order-by not optimized in sort-merge-join on salted tables

2018-01-08 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.13-cdh5.11.2 868fdaacd -> 506696f5e


PHOENIX-4508 Order-by not optimized in sort-merge-join on salted tables


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

Branch: refs/heads/4.13-cdh5.11.2
Commit: 506696f5e73220ea04ed92fc5fd57de0c6d36f59
Parents: 868fdaa
Author: maryannxue <maryann@gmail.com>
Authored: Mon Jan 8 11:26:15 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Mon Jan 8 11:26:15 2018 -0800

--
 .../phoenix/end2end/SortMergeJoinMoreIT.java| 108 +++
 .../compile/TupleProjectionCompiler.java|   7 +-
 2 files changed, 111 insertions(+), 4 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/506696f5/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
index e61332b..a132728 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
@@ -634,4 +634,112 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 }
 }
 }
+
+@Test
+public void testBug4508() throws Exception {
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+props.setProperty("TenantId", "010");
+Connection conn010 = DriverManager.getConnection(getUrl(), props);
+try {
+// Salted tables
+String peopleTable = generateUniqueName();
+String myTable = generateUniqueName();
+conn.createStatement().execute("CREATE TABLE " + peopleTable + " 
(\n" +
+"PERSON_ID VARCHAR NOT NULL,\n" +
+"NAME VARCHAR\n" +
+"CONSTRAINT PK_TEST_PEOPLE PRIMARY KEY (PERSON_ID)) 
SALT_BUCKETS = 3");
+conn.createStatement().execute("CREATE TABLE " + myTable + " (\n" +
+"LOCALID VARCHAR NOT NULL,\n" +
+"DSID VARCHAR(255) NOT NULL, \n" +
+"EID CHAR(40),\n" +
+"HAS_CANDIDATES BOOLEAN\n" +
+"CONSTRAINT PK_MYTABLE PRIMARY KEY (LOCALID, DSID)) 
SALT_BUCKETS = 3");
+verifyQueryPlanAndResultForBug4508(conn, peopleTable, myTable);
+
+// Salted multi-tenant tables
+String peopleTable2 = generateUniqueName();
+String myTable2 = generateUniqueName();
+conn.createStatement().execute("CREATE TABLE " + peopleTable2 + " 
(\n" +
+"TENANT_ID VARCHAR NOT NULL,\n" +
+"PERSON_ID VARCHAR NOT NULL,\n" +
+"NAME VARCHAR\n" +
+"CONSTRAINT PK_TEST_PEOPLE PRIMARY KEY (TENANT_ID, 
PERSON_ID))\n" +
+"SALT_BUCKETS = 3, MULTI_TENANT=true");
+conn.createStatement().execute("CREATE TABLE " + myTable2 + " (\n" 
+
+"TENANT_ID VARCHAR NOT NULL,\n" +
+"LOCALID VARCHAR NOT NULL,\n" +
+"DSID VARCHAR(255) NOT NULL, \n" +
+"EID CHAR(40),\n" +
+"HAS_CANDIDATES BOOLEAN\n" +
+"CONSTRAINT PK_MYTABLE PRIMARY KEY (TENANT_ID, LOCALID, 
DSID))\n" +
+"SALT_BUCKETS = 3, MULTI_TENANT=true");
+verifyQueryPlanAndResultForBug4508(conn010, peopleTable2, 
myTable2);
+} finally {
+conn.close();
+conn010.close();
+}
+}
+
+private static void verifyQueryPlanAndResultForBug4508(
+Connection conn, String peopleTable, String myTable) throws 
Exception {
+PreparedStatement peopleTableUpsertStmt = conn.prepareStatement(
+"UPSERT INTO " + peopleTable + " VALUES(?, ?)");
+peopleTableUpsertStmt.setString(1, "X001");
+peopleTableUpsertStmt.setString(2, "Marcus");
+  

phoenix git commit: PHOENIX-4508 Order-by not optimized in sort-merge-join on salted tables

2018-01-08 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/5.x-HBase-2.0 fdf4d0a69 -> d36d058a7


PHOENIX-4508 Order-by not optimized in sort-merge-join on salted tables


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

Branch: refs/heads/5.x-HBase-2.0
Commit: d36d058a72899eea2c47bca062c4eeaa75d4257c
Parents: fdf4d0a
Author: maryannxue <maryann@gmail.com>
Authored: Mon Jan 8 11:21:06 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Mon Jan 8 11:21:06 2018 -0800

--
 .../phoenix/end2end/SortMergeJoinMoreIT.java| 108 +++
 .../compile/TupleProjectionCompiler.java|   7 +-
 2 files changed, 111 insertions(+), 4 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/d36d058a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
index e61332b..a132728 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
@@ -634,4 +634,112 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 }
 }
 }
+
+@Test
+public void testBug4508() throws Exception {
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+props.setProperty("TenantId", "010");
+Connection conn010 = DriverManager.getConnection(getUrl(), props);
+try {
+// Salted tables
+String peopleTable = generateUniqueName();
+String myTable = generateUniqueName();
+conn.createStatement().execute("CREATE TABLE " + peopleTable + " 
(\n" +
+"PERSON_ID VARCHAR NOT NULL,\n" +
+"NAME VARCHAR\n" +
+"CONSTRAINT PK_TEST_PEOPLE PRIMARY KEY (PERSON_ID)) 
SALT_BUCKETS = 3");
+conn.createStatement().execute("CREATE TABLE " + myTable + " (\n" +
+"LOCALID VARCHAR NOT NULL,\n" +
+"DSID VARCHAR(255) NOT NULL, \n" +
+"EID CHAR(40),\n" +
+"HAS_CANDIDATES BOOLEAN\n" +
+"CONSTRAINT PK_MYTABLE PRIMARY KEY (LOCALID, DSID)) 
SALT_BUCKETS = 3");
+verifyQueryPlanAndResultForBug4508(conn, peopleTable, myTable);
+
+// Salted multi-tenant tables
+String peopleTable2 = generateUniqueName();
+String myTable2 = generateUniqueName();
+conn.createStatement().execute("CREATE TABLE " + peopleTable2 + " 
(\n" +
+"TENANT_ID VARCHAR NOT NULL,\n" +
+"PERSON_ID VARCHAR NOT NULL,\n" +
+"NAME VARCHAR\n" +
+"CONSTRAINT PK_TEST_PEOPLE PRIMARY KEY (TENANT_ID, 
PERSON_ID))\n" +
+"SALT_BUCKETS = 3, MULTI_TENANT=true");
+conn.createStatement().execute("CREATE TABLE " + myTable2 + " (\n" 
+
+"TENANT_ID VARCHAR NOT NULL,\n" +
+"LOCALID VARCHAR NOT NULL,\n" +
+"DSID VARCHAR(255) NOT NULL, \n" +
+"EID CHAR(40),\n" +
+"HAS_CANDIDATES BOOLEAN\n" +
+"CONSTRAINT PK_MYTABLE PRIMARY KEY (TENANT_ID, LOCALID, 
DSID))\n" +
+"SALT_BUCKETS = 3, MULTI_TENANT=true");
+verifyQueryPlanAndResultForBug4508(conn010, peopleTable2, 
myTable2);
+} finally {
+conn.close();
+conn010.close();
+}
+}
+
+private static void verifyQueryPlanAndResultForBug4508(
+Connection conn, String peopleTable, String myTable) throws 
Exception {
+PreparedStatement peopleTableUpsertStmt = conn.prepareStatement(
+"UPSERT INTO " + peopleTable + " VALUES(?, ?)");
+peopleTableUpsertStmt.setString(1, "X001");
+peopleTableUpsertStmt.setString(2, "Marcus");
+  

phoenix git commit: PHOENIX-4508 Order-by not optimized in sort-merge-join on salted tables

2018-01-08 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-cdh5.11.2 ddb69e14b -> 5fbdab5b7


PHOENIX-4508 Order-by not optimized in sort-merge-join on salted tables


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

Branch: refs/heads/4.x-cdh5.11.2
Commit: 5fbdab5b7f1bbdac25f1a238c1bfd302351f525d
Parents: ddb69e1
Author: maryannxue <maryann@gmail.com>
Authored: Mon Jan 8 11:15:05 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Mon Jan 8 11:15:05 2018 -0800

--
 .../phoenix/end2end/SortMergeJoinMoreIT.java| 108 +++
 .../compile/TupleProjectionCompiler.java|   7 +-
 2 files changed, 111 insertions(+), 4 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/5fbdab5b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
index e61332b..a132728 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
@@ -634,4 +634,112 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 }
 }
 }
+
+@Test
+public void testBug4508() throws Exception {
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+props.setProperty("TenantId", "010");
+Connection conn010 = DriverManager.getConnection(getUrl(), props);
+try {
+// Salted tables
+String peopleTable = generateUniqueName();
+String myTable = generateUniqueName();
+conn.createStatement().execute("CREATE TABLE " + peopleTable + " 
(\n" +
+"PERSON_ID VARCHAR NOT NULL,\n" +
+"NAME VARCHAR\n" +
+"CONSTRAINT PK_TEST_PEOPLE PRIMARY KEY (PERSON_ID)) 
SALT_BUCKETS = 3");
+conn.createStatement().execute("CREATE TABLE " + myTable + " (\n" +
+"LOCALID VARCHAR NOT NULL,\n" +
+"DSID VARCHAR(255) NOT NULL, \n" +
+"EID CHAR(40),\n" +
+"HAS_CANDIDATES BOOLEAN\n" +
+"CONSTRAINT PK_MYTABLE PRIMARY KEY (LOCALID, DSID)) 
SALT_BUCKETS = 3");
+verifyQueryPlanAndResultForBug4508(conn, peopleTable, myTable);
+
+// Salted multi-tenant tables
+String peopleTable2 = generateUniqueName();
+String myTable2 = generateUniqueName();
+conn.createStatement().execute("CREATE TABLE " + peopleTable2 + " 
(\n" +
+"TENANT_ID VARCHAR NOT NULL,\n" +
+"PERSON_ID VARCHAR NOT NULL,\n" +
+"NAME VARCHAR\n" +
+"CONSTRAINT PK_TEST_PEOPLE PRIMARY KEY (TENANT_ID, 
PERSON_ID))\n" +
+"SALT_BUCKETS = 3, MULTI_TENANT=true");
+conn.createStatement().execute("CREATE TABLE " + myTable2 + " (\n" 
+
+"TENANT_ID VARCHAR NOT NULL,\n" +
+"LOCALID VARCHAR NOT NULL,\n" +
+"DSID VARCHAR(255) NOT NULL, \n" +
+"EID CHAR(40),\n" +
+"HAS_CANDIDATES BOOLEAN\n" +
+"CONSTRAINT PK_MYTABLE PRIMARY KEY (TENANT_ID, LOCALID, 
DSID))\n" +
+"SALT_BUCKETS = 3, MULTI_TENANT=true");
+verifyQueryPlanAndResultForBug4508(conn010, peopleTable2, 
myTable2);
+} finally {
+conn.close();
+conn010.close();
+}
+}
+
+private static void verifyQueryPlanAndResultForBug4508(
+Connection conn, String peopleTable, String myTable) throws 
Exception {
+PreparedStatement peopleTableUpsertStmt = conn.prepareStatement(
+"UPSERT INTO " + peopleTable + " VALUES(?, ?)");
+peopleTableUpsertStmt.setString(1, "X001");
+peopleTableUpsertStmt.setString(2, "Marcus");
+  

phoenix git commit: PHOENIX-4508 Order-by not optimized in sort-merge-join on salted tables

2018-01-08 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.1 a2eaaa263 -> 8acdf98c1


PHOENIX-4508 Order-by not optimized in sort-merge-join on salted tables


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

Branch: refs/heads/4.x-HBase-1.1
Commit: 8acdf98c171ed8755e980042963867e3e74915a5
Parents: a2eaaa2
Author: maryannxue <maryann@gmail.com>
Authored: Mon Jan 8 11:09:33 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Mon Jan 8 11:09:33 2018 -0800

--
 .../phoenix/end2end/SortMergeJoinMoreIT.java| 108 +++
 .../compile/TupleProjectionCompiler.java|   7 +-
 2 files changed, 111 insertions(+), 4 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/8acdf98c/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
index e61332b..a132728 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
@@ -634,4 +634,112 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 }
 }
 }
+
+@Test
+public void testBug4508() throws Exception {
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+props.setProperty("TenantId", "010");
+Connection conn010 = DriverManager.getConnection(getUrl(), props);
+try {
+// Salted tables
+String peopleTable = generateUniqueName();
+String myTable = generateUniqueName();
+conn.createStatement().execute("CREATE TABLE " + peopleTable + " 
(\n" +
+"PERSON_ID VARCHAR NOT NULL,\n" +
+"NAME VARCHAR\n" +
+"CONSTRAINT PK_TEST_PEOPLE PRIMARY KEY (PERSON_ID)) 
SALT_BUCKETS = 3");
+conn.createStatement().execute("CREATE TABLE " + myTable + " (\n" +
+"LOCALID VARCHAR NOT NULL,\n" +
+"DSID VARCHAR(255) NOT NULL, \n" +
+"EID CHAR(40),\n" +
+"HAS_CANDIDATES BOOLEAN\n" +
+"CONSTRAINT PK_MYTABLE PRIMARY KEY (LOCALID, DSID)) 
SALT_BUCKETS = 3");
+verifyQueryPlanAndResultForBug4508(conn, peopleTable, myTable);
+
+// Salted multi-tenant tables
+String peopleTable2 = generateUniqueName();
+String myTable2 = generateUniqueName();
+conn.createStatement().execute("CREATE TABLE " + peopleTable2 + " 
(\n" +
+"TENANT_ID VARCHAR NOT NULL,\n" +
+"PERSON_ID VARCHAR NOT NULL,\n" +
+"NAME VARCHAR\n" +
+"CONSTRAINT PK_TEST_PEOPLE PRIMARY KEY (TENANT_ID, 
PERSON_ID))\n" +
+"SALT_BUCKETS = 3, MULTI_TENANT=true");
+conn.createStatement().execute("CREATE TABLE " + myTable2 + " (\n" 
+
+"TENANT_ID VARCHAR NOT NULL,\n" +
+"LOCALID VARCHAR NOT NULL,\n" +
+"DSID VARCHAR(255) NOT NULL, \n" +
+"EID CHAR(40),\n" +
+"HAS_CANDIDATES BOOLEAN\n" +
+"CONSTRAINT PK_MYTABLE PRIMARY KEY (TENANT_ID, LOCALID, 
DSID))\n" +
+"SALT_BUCKETS = 3, MULTI_TENANT=true");
+verifyQueryPlanAndResultForBug4508(conn010, peopleTable2, 
myTable2);
+} finally {
+conn.close();
+conn010.close();
+}
+}
+
+private static void verifyQueryPlanAndResultForBug4508(
+Connection conn, String peopleTable, String myTable) throws 
Exception {
+PreparedStatement peopleTableUpsertStmt = conn.prepareStatement(
+"UPSERT INTO " + peopleTable + " VALUES(?, ?)");
+peopleTableUpsertStmt.setString(1, "X001");
+peopleTableUpsertStmt.setString(2, "Marcus");
+  

phoenix git commit: PHOENIX-4508 Order-by not optimized in sort-merge-join on salted tables

2018-01-08 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.2 81748b2ea -> b49dcbde1


PHOENIX-4508 Order-by not optimized in sort-merge-join on salted tables


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

Branch: refs/heads/4.x-HBase-1.2
Commit: b49dcbde12b269d1f89569dc01565ba54a1d801d
Parents: 81748b2
Author: maryannxue <maryann@gmail.com>
Authored: Mon Jan 8 11:07:08 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Mon Jan 8 11:07:08 2018 -0800

--
 .../phoenix/end2end/SortMergeJoinMoreIT.java| 108 +++
 .../compile/TupleProjectionCompiler.java|   7 +-
 2 files changed, 111 insertions(+), 4 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/b49dcbde/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
index e61332b..a132728 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
@@ -634,4 +634,112 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 }
 }
 }
+
+@Test
+public void testBug4508() throws Exception {
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+props.setProperty("TenantId", "010");
+Connection conn010 = DriverManager.getConnection(getUrl(), props);
+try {
+// Salted tables
+String peopleTable = generateUniqueName();
+String myTable = generateUniqueName();
+conn.createStatement().execute("CREATE TABLE " + peopleTable + " 
(\n" +
+"PERSON_ID VARCHAR NOT NULL,\n" +
+"NAME VARCHAR\n" +
+"CONSTRAINT PK_TEST_PEOPLE PRIMARY KEY (PERSON_ID)) 
SALT_BUCKETS = 3");
+conn.createStatement().execute("CREATE TABLE " + myTable + " (\n" +
+"LOCALID VARCHAR NOT NULL,\n" +
+"DSID VARCHAR(255) NOT NULL, \n" +
+"EID CHAR(40),\n" +
+"HAS_CANDIDATES BOOLEAN\n" +
+"CONSTRAINT PK_MYTABLE PRIMARY KEY (LOCALID, DSID)) 
SALT_BUCKETS = 3");
+verifyQueryPlanAndResultForBug4508(conn, peopleTable, myTable);
+
+// Salted multi-tenant tables
+String peopleTable2 = generateUniqueName();
+String myTable2 = generateUniqueName();
+conn.createStatement().execute("CREATE TABLE " + peopleTable2 + " 
(\n" +
+"TENANT_ID VARCHAR NOT NULL,\n" +
+"PERSON_ID VARCHAR NOT NULL,\n" +
+"NAME VARCHAR\n" +
+"CONSTRAINT PK_TEST_PEOPLE PRIMARY KEY (TENANT_ID, 
PERSON_ID))\n" +
+"SALT_BUCKETS = 3, MULTI_TENANT=true");
+conn.createStatement().execute("CREATE TABLE " + myTable2 + " (\n" 
+
+"TENANT_ID VARCHAR NOT NULL,\n" +
+"LOCALID VARCHAR NOT NULL,\n" +
+"DSID VARCHAR(255) NOT NULL, \n" +
+"EID CHAR(40),\n" +
+"HAS_CANDIDATES BOOLEAN\n" +
+"CONSTRAINT PK_MYTABLE PRIMARY KEY (TENANT_ID, LOCALID, 
DSID))\n" +
+"SALT_BUCKETS = 3, MULTI_TENANT=true");
+verifyQueryPlanAndResultForBug4508(conn010, peopleTable2, 
myTable2);
+} finally {
+conn.close();
+conn010.close();
+}
+}
+
+private static void verifyQueryPlanAndResultForBug4508(
+Connection conn, String peopleTable, String myTable) throws 
Exception {
+PreparedStatement peopleTableUpsertStmt = conn.prepareStatement(
+"UPSERT INTO " + peopleTable + " VALUES(?, ?)");
+peopleTableUpsertStmt.setString(1, "X001");
+peopleTableUpsertStmt.setString(2, "Marcus");
+  

phoenix git commit: PHOENIX-4508 Order-by not optimized in sort-merge-join on salted tables

2018-01-08 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 a2b218e8d -> 488389e73


PHOENIX-4508 Order-by not optimized in sort-merge-join on salted tables


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

Branch: refs/heads/4.x-HBase-0.98
Commit: 488389e73575782f58be78baeb7410cdb6f1b17b
Parents: a2b218e
Author: maryannxue <maryann@gmail.com>
Authored: Mon Jan 8 11:04:11 2018 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Mon Jan 8 11:04:11 2018 -0800

--
 .../phoenix/end2end/SortMergeJoinMoreIT.java| 108 +++
 .../compile/TupleProjectionCompiler.java|   7 +-
 2 files changed, 111 insertions(+), 4 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/488389e7/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
index e61332b..a132728 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
@@ -634,4 +634,112 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 }
 }
 }
+
+@Test
+public void testBug4508() throws Exception {
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+Connection conn = DriverManager.getConnection(getUrl(), props);
+props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+props.setProperty("TenantId", "010");
+Connection conn010 = DriverManager.getConnection(getUrl(), props);
+try {
+// Salted tables
+String peopleTable = generateUniqueName();
+String myTable = generateUniqueName();
+conn.createStatement().execute("CREATE TABLE " + peopleTable + " 
(\n" +
+"PERSON_ID VARCHAR NOT NULL,\n" +
+"NAME VARCHAR\n" +
+"CONSTRAINT PK_TEST_PEOPLE PRIMARY KEY (PERSON_ID)) 
SALT_BUCKETS = 3");
+conn.createStatement().execute("CREATE TABLE " + myTable + " (\n" +
+"LOCALID VARCHAR NOT NULL,\n" +
+"DSID VARCHAR(255) NOT NULL, \n" +
+"EID CHAR(40),\n" +
+"HAS_CANDIDATES BOOLEAN\n" +
+"CONSTRAINT PK_MYTABLE PRIMARY KEY (LOCALID, DSID)) 
SALT_BUCKETS = 3");
+verifyQueryPlanAndResultForBug4508(conn, peopleTable, myTable);
+
+// Salted multi-tenant tables
+String peopleTable2 = generateUniqueName();
+String myTable2 = generateUniqueName();
+conn.createStatement().execute("CREATE TABLE " + peopleTable2 + " 
(\n" +
+"TENANT_ID VARCHAR NOT NULL,\n" +
+"PERSON_ID VARCHAR NOT NULL,\n" +
+"NAME VARCHAR\n" +
+"CONSTRAINT PK_TEST_PEOPLE PRIMARY KEY (TENANT_ID, 
PERSON_ID))\n" +
+"SALT_BUCKETS = 3, MULTI_TENANT=true");
+conn.createStatement().execute("CREATE TABLE " + myTable2 + " (\n" 
+
+"TENANT_ID VARCHAR NOT NULL,\n" +
+"LOCALID VARCHAR NOT NULL,\n" +
+"DSID VARCHAR(255) NOT NULL, \n" +
+"EID CHAR(40),\n" +
+"HAS_CANDIDATES BOOLEAN\n" +
+"CONSTRAINT PK_MYTABLE PRIMARY KEY (TENANT_ID, LOCALID, 
DSID))\n" +
+"SALT_BUCKETS = 3, MULTI_TENANT=true");
+verifyQueryPlanAndResultForBug4508(conn010, peopleTable2, 
myTable2);
+} finally {
+conn.close();
+conn010.close();
+}
+}
+
+private static void verifyQueryPlanAndResultForBug4508(
+Connection conn, String peopleTable, String myTable) throws 
Exception {
+PreparedStatement peopleTableUpsertStmt = conn.prepareStatement(
+"UPSERT INTO " + peopleTable + " VALUES(?, ?)");
+peopleTableUpsertStmt.setString(1, "X001");
+peopleTableUpsertStmt.setString(2, "Marcus");
+  

phoenix git commit: PHOENIX-4437 Make QueryPlan.getEstimatedBytesToScan() independent of getExplainPlan() and pull optimize() out of getExplainPlan()

2017-12-21 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/master 9355a4d26 -> 412329a74


PHOENIX-4437 Make QueryPlan.getEstimatedBytesToScan() independent of 
getExplainPlan() and pull optimize() out of getExplainPlan()


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

Branch: refs/heads/master
Commit: 412329a7415302831954891285d291055328c28b
Parents: 9355a4d
Author: maryannxue <maryann@gmail.com>
Authored: Thu Dec 21 10:31:04 2017 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Thu Dec 21 10:31:04 2017 -0800

--
 .../end2end/ExplainPlanWithStatsEnabledIT.java  |  2 +-
 .../apache/phoenix/execute/BaseQueryPlan.java   | 45 ++
 .../apache/phoenix/execute/HashJoinPlan.java| 59 +-
 .../phoenix/execute/SortMergeJoinPlan.java  | 63 ++--
 .../org/apache/phoenix/execute/UnionPlan.java   | 53 
 .../apache/phoenix/jdbc/PhoenixStatement.java   |  9 ++-
 6 files changed, 119 insertions(+), 112 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/412329a7/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java
index 49efa97..f13510b 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/ExplainPlanWithStatsEnabledIT.java
@@ -298,7 +298,7 @@ public class ExplainPlanWithStatsEnabledIT extends 
ParallelStatsEnabledIT {
 try (Connection conn = DriverManager.getConnection(getUrl())) {
 conn.setAutoCommit(false);
 Estimate info = getByteRowEstimates(conn, sql, binds);
-assertEquals((Long) 200l, info.estimatedBytes);
+assertEquals((Long) 176l, info.estimatedBytes);
 assertEquals((Long) 2l, info.estimatedRows);
 assertTrue(info.estimateInfoTs > 0);
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/412329a7/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
index 31f67b7..380037f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/BaseQueryPlan.java
@@ -117,7 +117,7 @@ public abstract class BaseQueryPlan implements QueryPlan {
 protected Long estimatedRows;
 protected Long estimatedSize;
 protected Long estimateInfoTimestamp;
-private boolean explainPlanCalled;
+private boolean getEstimatesCalled;
 
 
 protected BaseQueryPlan(
@@ -498,32 +498,17 @@ public abstract class BaseQueryPlan implements QueryPlan {
 
 @Override
 public ExplainPlan getExplainPlan() throws SQLException {
-explainPlanCalled = true;
 if (context.getScanRanges() == ScanRanges.NOTHING) {
 return new ExplainPlan(Collections.singletonList("DEGENERATE SCAN 
OVER " + getTableRef().getTable().getName().getString()));
 }
 
-// If cost-based optimizer is enabled, we need to initialize a dummy 
iterator to
-// get the stats for computing costs.
-boolean costBased =
-
context.getConnection().getQueryServices().getConfiguration().getBoolean(
-QueryServices.COST_BASED_OPTIMIZER_ENABLED, 
QueryServicesOptions.DEFAULT_COST_BASED_OPTIMIZER_ENABLED);
-if (costBased) {
-ResultIterator iterator = iterator();
-iterator.close();
-}
-// Optimize here when getting explain plan, as queries don't get 
optimized until after compilation
-QueryPlan plan = 
context.getConnection().getQueryServices().getOptimizer().optimize(context.getStatement(),
 this);
-ExplainPlan exp = plan instanceof BaseQueryPlan ? new 
ExplainPlan(getPlanSteps(plan.iterator())) : plan.getExplainPlan();
-if (!costBased) { // do not override estimates if they are used for 
cost calculation.
-this.estimatedRows = plan.getEstimatedRowsToScan();
-this.estimatedSize = plan.getEstimatedBytesToScan();
-this.estimateInfoTimestamp = plan.getEstimateInfoTimestamp();
- 

phoenix git commit: PHOENIX-3050 Handle DESC columns in child/parent join optimization

2017-12-06 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/master d77c237b5 -> 071fbce49


PHOENIX-3050 Handle DESC columns in child/parent join optimization


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

Branch: refs/heads/master
Commit: 071fbce499c5303ffdcd4bbe25c1cda788aced0c
Parents: d77c237
Author: maryannxue <maryann@gmail.com>
Authored: Wed Dec 6 12:07:16 2017 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Wed Dec 6 12:07:16 2017 -0800

--
 .../phoenix/end2end/join/HashJoinMoreIT.java |  5 +
 .../org/apache/phoenix/compile/JoinCompiler.java | 19 +--
 .../apache/phoenix/compile/QueryCompiler.java|  6 +++---
 .../apache/phoenix/compile/WhereOptimizer.java   |  5 -
 4 files changed, 21 insertions(+), 14 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/071fbce4/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
index 37ffd02..f09f1d3 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/join/HashJoinMoreIT.java
@@ -895,6 +895,11 @@ public class HashJoinMoreIT extends 
ParallelStatsDisabledIT {
 + "FROM ( SELECT ACCOUNT_ID, BUCKET_ID, OBJECT_ID, 
MAX(OBJECT_VERSION) AS MAXVER "
 + "   FROM test2961 GROUP BY ACCOUNT_ID, BUCKET_ID, 
OBJECT_ID) AS X "
 + "   INNER JOIN test2961 AS OBJ ON X.ACCOUNT_ID = 
OBJ.ACCOUNT_ID AND X.BUCKET_ID = OBJ.BUCKET_ID AND X.OBJECT_ID = OBJ.OBJECT_ID 
AND  X.MAXVER = OBJ.OBJECT_VERSION";
+rs = conn.createStatement().executeQuery("explain " + q);
+String plan = QueryUtil.getExplainPlan(rs);
+String dynamicFilter = "DYNAMIC SERVER FILTER BY (OBJ.ACCOUNT_ID, 
OBJ.BUCKET_ID, OBJ.OBJECT_ID, OBJ.OBJECT_VERSION) IN ((X.ACCOUNT_ID, 
X.BUCKET_ID, X.OBJECT_ID, X.MAXVER))";
+assertTrue("Expected '" + dynamicFilter + "' to be used for the 
query, but got:\n" + plan,
+plan.contains(dynamicFilter));
 rs = conn.createStatement().executeQuery(q);
 assertTrue(rs.next());
 assertEquals("", rs.getString(4));

http://git-wip-us.apache.org/repos/asf/phoenix/blob/071fbce4/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
index 887e2d2..439a79b 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/JoinCompiler.java
@@ -110,6 +110,12 @@ import com.google.common.collect.Sets;
 
 public class JoinCompiler {
 
+public enum Strategy {
+HASH_BUILD_LEFT,
+HASH_BUILD_RIGHT,
+SORT_MERGE,
+}
+
 public enum ColumnRefType {
 JOINLOCAL,
 GENERAL,
@@ -489,7 +495,7 @@ public class JoinCompiler {
 return dependencies;
 }
 
-public Pair<List, List> 
compileJoinConditions(StatementContext lhsCtx, StatementContext rhsCtx, boolean 
sortExpressions) throws SQLException {
+public Pair<List, List> 
compileJoinConditions(StatementContext lhsCtx, StatementContext rhsCtx, 
Strategy strategy) throws SQLException {
 if (onConditions.isEmpty()) {
 return new Pair<List, List>(
 Collections. 
singletonList(LiteralExpression.newConstant(1)),
@@ -505,15 +511,16 @@ public class JoinCompiler {
 rhsCompiler.reset();
 Expression right = condition.getRHS().accept(rhsCompiler);
 PDataType toType = getCommonType(left.getDataType(), 
right.getDataType());
-if (left.getDataType() != toType || left.getSortOrder() == 
SortOrder.DESC) {
-left = CoerceExpression.create(left, toType, 
SortOrder.ASC, left.getMaxLength());
+SortOrder toSortOrder = strategy == Strategy.SORT_MERGE ? 
SortOrder.ASC : (strategy == Strategy.HASH_BUILD_LEFT ? right.getSortOrder() : 
left.getSortOrder());
+if (left.getDataTy

phoenix git commit: PHOENIX-4322 DESC primary key column with variable length does not work in SkipScanFilter

2017-12-05 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/master 6807dacce -> d77c237b5


PHOENIX-4322 DESC primary key column with variable length does not work in 
SkipScanFilter


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

Branch: refs/heads/master
Commit: d77c237b560900671c3a9c58f6f2398342655e8a
Parents: 6807dac
Author: maryannxue <maryann@gmail.com>
Authored: Tue Dec 5 10:59:41 2017 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Tue Dec 5 10:59:41 2017 -0800

--
 .../it/java/org/apache/phoenix/end2end/SortOrderIT.java  | 11 ++-
 .../expression/RowValueConstructorExpression.java|  4 ++--
 2 files changed, 12 insertions(+), 3 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/d77c237b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
index 655dbb1..3f749c1 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
@@ -167,7 +167,16 @@ public class SortOrderIT extends ParallelStatsDisabledIT {
 runQueryTest(ddl, upsert("oid", "code"), insertedRows, new 
Object[][]{{"o2", 2}}, new WhereCondition("oid", "IN", "('o2')"),
 table);
 }
-
+
+@Test
+public void inDescCompositePK3() throws Exception {
+String table = generateUniqueName();
+String ddl = "CREATE table " + table + " (oid VARCHAR NOT NULL, code 
VARCHAR NOT NULL constraint pk primary key (oid DESC, code DESC))";
+Object[][] insertedRows = new Object[][]{{"o1", "1"}, {"o2", "2"}, 
{"o3", "3"}};
+runQueryTest(ddl, upsert("oid", "code"), insertedRows, new 
Object[][]{{"o2", "2"}, {"o1", "1"}}, new WhereCondition("(oid, code)", "IN", 
"(('o2', '2'), ('o1', '1'))"),
+table);
+}
+
 @Test
 public void likeDescCompositePK1() throws Exception {
 String table = generateUniqueName();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d77c237b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
index 15f6e3e..9bb7234 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/expression/RowValueConstructorExpression.java
@@ -199,8 +199,8 @@ public class RowValueConstructorExpression extends 
BaseCompoundExpression {
 // as otherwise we need it to ensure sort order is correct
 for (int k = expressionCount -1 ; 
 k >=0 &&  getChildren().get(k).getDataType() != 
null 
-  && 
!getChildren().get(k).getDataType().isFixedWidth() 
-  && outputBytes[outputSize-1] == 
QueryConstants.SEPARATOR_BYTE ; k--) {
+  && 
!getChildren().get(k).getDataType().isFixedWidth()
+  && outputBytes[outputSize-1] == 
SchemaUtil.getSeparatorByte(true, false, getChildren().get(k)) ; k--) {
 outputSize--;
 }
 ptr.set(outputBytes, 0, outputSize);



phoenix git commit: PHOENIX-4288 Indexes not used when ordering by primary key

2017-12-05 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/master 88038a2da -> 6807dacce


PHOENIX-4288 Indexes not used when ordering by primary key


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

Branch: refs/heads/master
Commit: 6807dacce7d063e14f06bc57888e7d2a5f78863a
Parents: 88038a2
Author: maryannxue <maryann@gmail.com>
Authored: Tue Dec 5 10:52:46 2017 -0800
Committer: maryannxue <maryann@gmail.com>
Committed: Tue Dec 5 10:52:46 2017 -0800

--
 .../phoenix/end2end/CostBasedDecisionIT.java| 466 +++
 .../apache/phoenix/end2end/MutationStateIT.java |  17 +
 .../apache/phoenix/end2end/SystemCatalogIT.java |  17 +
 .../phoenix/compile/ListJarsQueryPlan.java  |   6 +
 .../org/apache/phoenix/compile/QueryPlan.java   |   5 +-
 .../apache/phoenix/compile/TraceQueryPlan.java  |   6 +
 .../apache/phoenix/execute/AggregatePlan.java   |  30 +-
 .../apache/phoenix/execute/BaseQueryPlan.java   |  21 +-
 .../phoenix/execute/ClientAggregatePlan.java|  28 ++
 .../apache/phoenix/execute/ClientScanPlan.java  |  25 +
 .../apache/phoenix/execute/CorrelatePlan.java   |  25 +
 .../phoenix/execute/DelegateQueryPlan.java  |   6 +
 .../apache/phoenix/execute/HashJoinPlan.java|  29 ++
 .../execute/LiteralResultIterationPlan.java |   6 +
 .../org/apache/phoenix/execute/ScanPlan.java|  25 +
 .../phoenix/execute/SortMergeJoinPlan.java  |  18 +
 .../org/apache/phoenix/execute/UnionPlan.java   |  10 +
 .../apache/phoenix/jdbc/PhoenixStatement.java   |   6 +
 .../java/org/apache/phoenix/optimize/Cost.java  | 123 +
 .../apache/phoenix/optimize/QueryOptimizer.java |  30 +-
 .../org/apache/phoenix/query/QueryServices.java |   3 +
 .../phoenix/query/QueryServicesOptions.java |   4 +
 .../java/org/apache/phoenix/util/CostUtil.java  |  90 
 .../query/ParallelIteratorsSplitTest.java   |   6 +
 24 files changed, 988 insertions(+), 14 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/6807dacc/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
new file mode 100644
index 000..a3584ce
--- /dev/null
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CostBasedDecisionIT.java
@@ -0,0 +1,466 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end;
+
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.Map;
+import java.util.Properties;
+
+import org.apache.phoenix.query.BaseTest;
+import org.apache.phoenix.query.QueryServices;
+import org.apache.phoenix.util.PropertiesUtil;
+import org.apache.phoenix.util.QueryUtil;
+import org.apache.phoenix.util.ReadOnlyProps;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.google.common.collect.Maps;
+
+public class CostBasedDecisionIT extends BaseUniqueNamesOwnClusterIT {
+
+@BeforeClass
+public static void doSetup() throws Exception {
+Map<String, String> props = Maps.newHashMapWithExpectedSize(1);
+props.put(QueryServices.STATS_GUIDEPOST_WIDTH_BYTES_ATTRIB, 
Long.toString(20));
+props.put(QueryServices.STATS_UPDATE_FREQ_MS_ATTRIB, Long.toString(5));
+props.put(QueryServices.USE_STATS_FOR_PARALLELIZATION, 
Boolean.toString(true));
+props.put(QueryServices.COST_BASED_OPTIMIZER_ENABLED, 
Boolean.toString(true));
+setUpTestDriver(new ReadOnlyProps(props.entrySet().iterator(

phoenix git commit: PHOENIX-4322 DESC primary key column with variable length does not work in SkipScanFilter (fix test failures)

2017-10-30 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/master b0220fa75 -> 45a9c275d


PHOENIX-4322 DESC primary key column with variable length does not work in 
SkipScanFilter (fix test failures)


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

Branch: refs/heads/master
Commit: 45a9c275dbbf9206264236c690f40c309d97da3c
Parents: b0220fa
Author: maryannxue <maryann@gmail.com>
Authored: Mon Oct 30 15:13:43 2017 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Mon Oct 30 15:13:43 2017 -0700

--
 phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/45a9c275/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
--
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java 
b/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
index 8ab4f20..3fe8ad3 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
@@ -434,7 +434,7 @@ public class ScanUtil {
 // The result of an RVC evaluation can come with a trailing 
separator already, so we
 // should avoid adding another one.
 if ( !isFixedWidth
-&& ( bytes.length == 0 || key[offset - 1] != sepByte )
+&& ( bytes.length == 0 || slotSpan[i] == 0 || key[offset - 
1] != sepByte )
 && ( sepByte == QueryConstants.DESC_SEPARATOR_BYTE
 || ( !exclusiveUpper 
  && (fieldIndex < 
schema.getMaxFields() || inclusiveUpper || exclusiveLower) ) ) ) {



phoenix git commit: PHOENIX-4322 DESC primary key column with variable length does not work in SkipScanFilter

2017-10-30 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/master 0c38f493c -> b0220fa75


PHOENIX-4322 DESC primary key column with variable length does not work in 
SkipScanFilter


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

Branch: refs/heads/master
Commit: b0220fa7522fd7e1848ad428a47121b205dec504
Parents: 0c38f49
Author: maryannxue <maryann@gmail.com>
Authored: Mon Oct 30 11:49:40 2017 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Mon Oct 30 11:49:40 2017 -0700

--
 .../src/it/java/org/apache/phoenix/end2end/SortOrderIT.java | 9 +
 .../src/main/java/org/apache/phoenix/util/ScanUtil.java | 7 +--
 2 files changed, 14 insertions(+), 2 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/b0220fa7/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
index 655dbb1..58bbabb 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortOrderIT.java
@@ -167,6 +167,15 @@ public class SortOrderIT extends ParallelStatsDisabledIT {
 runQueryTest(ddl, upsert("oid", "code"), insertedRows, new 
Object[][]{{"o2", 2}}, new WhereCondition("oid", "IN", "('o2')"),
 table);
 }
+
+@Test
+public void inDescCompositePK3() throws Exception {
+String table = generateUniqueName();
+String ddl = "CREATE table " + table + " (oid INTEGER NOT NULL, code 
VARCHAR NOT NULL constraint pk primary key (oid DESC, code DESC))";
+Object[][] insertedRows = new Object[][]{{1, "o1"}, {2, "o2"}, {3, 
"o3"}};
+runQueryTest(ddl, upsert("oid", "code"), insertedRows, new 
Object[][]{{2, "o2"}, {1, "o1"}},
+new WhereCondition("(oid, code)", "IN", "((1, 'o1'), (2, 'o2'))"), 
table);
+}
 
 @Test
 public void likeDescCompositePK1() throws Exception {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b0220fa7/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
--
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java 
b/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
index a844226..8ab4f20 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/ScanUtil.java
@@ -431,8 +431,11 @@ public class ScanUtil {
 anyInclusiveUpperRangeKey |= !range.isSingleKey() && 
inclusiveUpper;
 // A null or empty byte array is always represented as a zero byte
 byte sepByte = 
SchemaUtil.getSeparatorByte(schema.rowKeyOrderOptimizable(), bytes.length == 0, 
field);
-
-if ( !isFixedWidth && ( sepByte == 
QueryConstants.DESC_SEPARATOR_BYTE 
+// The result of an RVC evaluation can come with a trailing 
separator already, so we
+// should avoid adding another one.
+if ( !isFixedWidth
+&& ( bytes.length == 0 || key[offset - 1] != sepByte )
+&& ( sepByte == QueryConstants.DESC_SEPARATOR_BYTE
 || ( !exclusiveUpper 
  && (fieldIndex < 
schema.getMaxFields() || inclusiveUpper || exclusiveLower) ) ) ) {
 key[offset++] = sepByte;



phoenix git commit: Fix broken compilation due to Calcite interface change

2017-08-31 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/calcite c0961ebfe -> bea429aad


Fix broken compilation due to Calcite interface change


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

Branch: refs/heads/calcite
Commit: bea429aada2e68ef529ae6cf14bd63111ef8c27c
Parents: c0961eb
Author: maryannxue <maryann@gmail.com>
Authored: Thu Aug 31 12:15:52 2017 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Thu Aug 31 12:15:52 2017 -0700

--
 .../apache/phoenix/calcite/PhoenixSchema.java   | 10 +++-
 .../phoenix/calcite/PhoenixSqlConformance.java  | 24 ++--
 .../phoenix/calcite/ToExpressionTest.java   |  8 ++-
 3 files changed, 7 insertions(+), 35 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/bea429aa/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
index b17e0aa..4ef0898 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
@@ -24,6 +24,7 @@ import org.apache.calcite.schema.FunctionParameter;
 import org.apache.calcite.schema.Schema;
 import org.apache.calcite.schema.SchemaFactory;
 import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.schema.SchemaVersion;
 import org.apache.calcite.schema.Table;
 import org.apache.calcite.schema.impl.TableFunctionImpl;
 import org.apache.calcite.schema.impl.ViewTable;
@@ -551,15 +552,10 @@ public class PhoenixSchema implements Schema {
 }
 
 @Override
-public boolean contentsHaveChangedSince(long lastCheck, long now) {
-return lastCheck != now;
-}
-
-@Override
-public Schema snapshot(long now) {
+public Schema snapshot(SchemaVersion version) {
 return new PhoenixSchema(name, schemaName, parentSchema, pc, 
typeFactory);
 }
-
+
 public void defineIndexesAsMaterializations(SchemaPlus parentSchema) {
 SchemaPlus schema = parentSchema.getSubSchema(this.name);
 SchemaPlus viewSqlSchema =

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bea429aa/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSqlConformance.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSqlConformance.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSqlConformance.java
index 9e45198..bf311c7 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSqlConformance.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSqlConformance.java
@@ -17,9 +17,9 @@
  */
 package org.apache.phoenix.calcite;
 
-import org.apache.calcite.sql.validate.SqlConformance;
+import org.apache.calcite.sql.validate.SqlAbstractConformance;
 
-public class PhoenixSqlConformance implements SqlConformance {
+public class PhoenixSqlConformance extends SqlAbstractConformance {
 
 public static final PhoenixSqlConformance INSTANCE =
 new PhoenixSqlConformance();
@@ -37,11 +37,6 @@ public class PhoenixSqlConformance implements SqlConformance 
{
 }
 
 @Override
-public boolean isSortByAliasObscures() {
-return false;
-}
-
-@Override
 public boolean isFromRequired() {
 return false;
 }
@@ -52,16 +47,6 @@ public class PhoenixSqlConformance implements SqlConformance 
{
 }
 
 @Override
-public boolean isMinusAllowed() {
-return false;
-}
-
-@Override
-public boolean isApplyAllowed() {
-return false;
-}
-
-@Override
 public boolean isInsertSubsetColumnsAllowed() {
 return true;
 }
@@ -90,9 +75,4 @@ public class PhoenixSqlConformance implements SqlConformance {
 public boolean allowExtend() {
 return true;
 }
-
-@Override
-public boolean isLimitStartCountAllowed() {
-return false;
-}
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/bea429aa/phoenix-core/src/test/java/org/apache/phoenix/calcite/ToExpressionTest.java
--
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/calcite/ToExpressionTest.java 
b/phoenix-core/src/test/java/org/apache/phoenix/calcite/ToExpressionTest.java
index 5bfc77b..648cd37 100644
--- 
a/phoenix-core/src/test/java/org/apache/

phoenix git commit: Fix regression caused by PHOENIX-3341

2017-08-03 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/calcite b7e5ae4b1 -> c0961ebfe


Fix regression caused by PHOENIX-3341


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

Branch: refs/heads/calcite
Commit: c0961ebfec45d3d4f9203ca63c3c525636c379c5
Parents: b7e5ae4
Author: maryannxue <maryann@gmail.com>
Authored: Thu Aug 3 12:20:52 2017 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Thu Aug 3 12:20:52 2017 -0700

--
 .../java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java   | 4 ++--
 .../main/java/org/apache/phoenix/calcite/PhoenixSchema.java   | 7 +--
 2 files changed, 3 insertions(+), 8 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/c0961ebf/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java
index bd7450e..7ec7552 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java
@@ -248,9 +248,9 @@ public class PhoenixPrepareImpl extends CalcitePrepareImpl {
 public Object apply(RelNode root) {
 for (CalciteSchema schema : 
rootSchema.getSubSchemaMap().values()) {
 if (schema.schema instanceof PhoenixSchema) {
-((PhoenixSchema) 
schema.schema).defineIndexesAsMaterializations();
+((PhoenixSchema) 
schema.schema).defineIndexesAsMaterializations(schema.plus().getParentSchema());
 for (CalciteSchema subSchema : 
schema.getSubSchemaMap().values()) {
-((PhoenixSchema) 
subSchema.schema).defineIndexesAsMaterializations();
+((PhoenixSchema) 
subSchema.schema).defineIndexesAsMaterializations(subSchema.plus().getParentSchema());
 }
 }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/c0961ebf/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
index bedec19..b17e0aa 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
@@ -54,12 +54,7 @@ import 
org.apache.phoenix.parse.FunctionParseNode.FunctionClassType;
 import org.apache.phoenix.parse.NamedTableNode;
 import org.apache.phoenix.parse.PFunction;
 import org.apache.phoenix.parse.PFunction.FunctionArgument;
-import org.apache.phoenix.parse.ColumnParseNode;
-import org.apache.phoenix.parse.ParseNode;
 import org.apache.phoenix.parse.ParseNodeFactory;
-import org.apache.phoenix.parse.ParseNodeRewriter;
-import org.apache.phoenix.parse.ParseNodeVisitor;
-import org.apache.phoenix.parse.SQLParser;
 import org.apache.phoenix.parse.SequenceValueParseNode;
 import org.apache.phoenix.parse.TableName;
 import org.apache.phoenix.query.QueryServices;
@@ -565,7 +560,7 @@ public class PhoenixSchema implements Schema {
 return new PhoenixSchema(name, schemaName, parentSchema, pc, 
typeFactory);
 }
 
-public void defineIndexesAsMaterializations() {
+public void defineIndexesAsMaterializations(SchemaPlus parentSchema) {
 SchemaPlus schema = parentSchema.getSubSchema(this.name);
 SchemaPlus viewSqlSchema =
 this.schemaName == null ? schema : parentSchema;



phoenix git commit: Fix compilation error; Fix a regression due to Calcite materialization changes

2017-08-02 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/calcite 17c206434 -> b7e5ae4b1


Fix compilation error; Fix a regression due to Calcite materialization changes


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

Branch: refs/heads/calcite
Commit: b7e5ae4b17d99e13e6ff90242b8e39312d54edf5
Parents: 17c2064
Author: maryannxue <maryann@gmail.com>
Authored: Wed Aug 2 16:13:01 2017 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Wed Aug 2 16:13:01 2017 -0700

--
 .../apache/phoenix/calcite/PhoenixPrograms.java| 12 +---
 .../phoenix/calcite/PhoenixSqlConformance.java |  5 +
 .../apache/phoenix/compile/QueryOptimizerTest.java | 17 -
 3 files changed, 14 insertions(+), 20 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/b7e5ae4b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrograms.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrograms.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrograms.java
index 4c7454a..9e0412e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrograms.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrograms.java
@@ -2,7 +2,6 @@ package org.apache.phoenix.calcite;
 
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
@@ -144,24 +143,15 @@ public class PhoenixPrograms {
 List materializations,
 List lattices) {
 final List<Pair<RelNode, List>> 
materializationUses;
-final Set applicableMaterializations;
+final Set applicableMaterializations = 
Collections.emptySet();
 final CalciteConnectionConfig config =
 
planner.getContext().unwrap(CalciteConnectionConfig.class);
 if (config != null && config.materializationsEnabled()) {
 // Transform rels using materialized views.
 materializationUses =
 RelOptMaterializations.useMaterializedViews(rel, 
materializations);
-
-// Add not used but potentially useful materialized views 
to the planner.
-applicableMaterializations = new HashSet<>(
-
RelOptMaterializations.getApplicableMaterializations(
-rel, materializations));
-for (Pair<RelNode, List> use : 
materializationUses) {
-applicableMaterializations.removeAll(use.right);
-}
 } else {
 materializationUses = Collections.emptyList();
-applicableMaterializations = Collections.emptySet();
 }
 
 final List rules = planner.getRules();

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b7e5ae4b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSqlConformance.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSqlConformance.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSqlConformance.java
index 77bd75e..9e45198 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSqlConformance.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSqlConformance.java
@@ -90,4 +90,9 @@ public class PhoenixSqlConformance implements SqlConformance {
 public boolean allowExtend() {
 return true;
 }
+
+@Override
+public boolean isLimitStartCountAllowed() {
+return false;
+}
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b7e5ae4b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java
--
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java 
b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java
index 9a624be..7aff096 100644
--- 
a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java
@@ -463,7 +463,7 @@ public class QueryOptimizerTest extends 
BaseConnectionlessQueryTest {
 strArray[1] = "CD";
 Array array = conn.creat

phoenix git commit: PHOENIX-3341 Schema update is not visible to following statements of the same connection due to CalciteSchema caching.

2017-05-24 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/calcite 4075d76e5 -> d2b995c83


PHOENIX-3341 Schema update is not visible to following statements of the same 
connection due to CalciteSchema caching.


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

Branch: refs/heads/calcite
Commit: d2b995c838e03699f58e33e4d91cbd19bfe62bc8
Parents: 4075d76
Author: maryannxue <maryann@gmail.com>
Authored: Wed May 24 21:35:26 2017 +0800
Committer: maryannxue <maryann@gmail.com>
Committed: Wed May 24 21:35:26 2017 +0800

--
 .../phoenix/calcite/PhoenixPrepareImpl.java | 20 
 .../apache/phoenix/calcite/PhoenixSchema.java   | 11 ---
 .../phoenix/calcite/ToExpressionTest.java   |  5 +
 3 files changed, 9 insertions(+), 27 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/d2b995c8/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java
index 91b0cb6..1ee84f0 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java
@@ -23,19 +23,14 @@ import org.apache.calcite.plan.RelOptCostFactory;
 import org.apache.calcite.plan.RelOptPlanner;
 import org.apache.calcite.plan.RelOptRule;
 import org.apache.calcite.prepare.CalcitePrepareImpl;
-import org.apache.calcite.prepare.Prepare.PreparedResult;
 import org.apache.calcite.rel.RelNode;
-import org.apache.calcite.rel.RelRoot;
 import org.apache.calcite.rel.convert.ConverterRule;
-import org.apache.calcite.rel.type.RelDataType;
 import org.apache.calcite.rex.RexBuilder;
 import org.apache.calcite.runtime.Hook;
 import org.apache.calcite.runtime.Hook.Closeable;
 import org.apache.calcite.schema.SchemaPlus;
 import org.apache.calcite.sql.SqlColumnDefInPkConstraintNode;
 import org.apache.calcite.sql.SqlColumnDefNode;
-import org.apache.calcite.sql.SqlExplainFormat;
-import org.apache.calcite.sql.SqlExplainLevel;
 import org.apache.calcite.sql.SqlFunctionArguementNode;
 import org.apache.calcite.sql.SqlIdentifier;
 import org.apache.calcite.sql.SqlIndexExpressionNode;
@@ -248,21 +243,6 @@ public class PhoenixPrepareImpl extends CalcitePrepareImpl 
{
 boolean materializationEnabled, final boolean forceDecorrelate) {
 final List hooks = Lists.newArrayList();
 
-hooks.add(Hook.PARSE_TREE.add(new Function<Object[], Object>() {
-@Override
-public Object apply(Object[] input) {
-for (CalciteSchema schema : 
rootSchema.getSubSchemaMap().values()) {
-if (schema.schema instanceof PhoenixSchema) {
-((PhoenixSchema) schema.schema).clear();
-for (CalciteSchema subSchema : 
schema.getSubSchemaMap().values()) {
-((PhoenixSchema) subSchema.schema).clear();
-}
-}
-}
-return null;
-}
-}));
-
 hooks.add(Hook.TRIMMED.add(new Function<RelNode, Object>() {
 @Override
 public Object apply(RelNode root) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d2b995c8/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
index 315556a..6d9afdf 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixSchema.java
@@ -13,7 +13,6 @@ import org.apache.calcite.materialize.MaterializationService;
 import org.apache.calcite.rel.type.RelDataType;
 import org.apache.calcite.rel.type.RelDataTypeFactory;
 import org.apache.calcite.schema.*;
-import org.apache.calcite.schema.Table;
 import org.apache.calcite.schema.impl.TableFunctionImpl;
 import org.apache.calcite.schema.impl.ViewTable;
 import org.apache.calcite.sql.ListJarsTable;
@@ -438,12 +437,10 @@ public class PhoenixSchema implements Schema {
 public boolean contentsHaveChangedSince(long lastCheck, long now) {
 return lastCheck != now;
 }
-
-public void clear() {
-tables.cl

[2/2] phoenix git commit: PHOENIX-3785 Replace unwrap(PhoenixStatement.class) with new Calcite-Phoenix statement classes

2017-04-12 Thread maryannxue
PHOENIX-3785 Replace unwrap(PhoenixStatement.class) with new Calcite-Phoenix 
statement classes


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

Branch: refs/heads/calcite
Commit: d9caed0a8cb10b6aae3e3c22b73e9dd5b8a2a05a
Parents: a78e008
Author: maryannxue <maryann@gmail.com>
Authored: Wed Apr 12 22:10:21 2017 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Wed Apr 12 22:10:21 2017 -0700

--
 .../AlterMultiTenantTableWithViewsIT.java   |   9 +-
 .../org/apache/phoenix/end2end/BaseViewIT.java  |  10 +-
 .../apache/phoenix/end2end/CreateTableIT.java   |  13 +-
 .../apache/phoenix/end2end/GroupByCaseIT.java   |   7 +-
 .../phoenix/end2end/ParallelIteratorsIT.java|   7 +-
 .../apache/phoenix/end2end/QueryTimeoutIT.java  |   7 +-
 .../org/apache/phoenix/end2end/SequenceIT.java  |   7 +-
 .../phoenix/end2end/SerialIteratorsIT.java  |   5 +-
 .../apache/phoenix/end2end/UpsertSelectIT.java  |   6 +-
 .../apache/phoenix/end2end/UpsertValuesIT.java  |   8 +-
 .../apache/phoenix/end2end/index/IndexIT.java   |   9 +-
 .../phoenix/end2end/index/LocalIndexIT.java |   8 +-
 .../phoenix/end2end/index/ViewIndexIT.java  |  16 +-
 .../phoenix/iterate/PhoenixQueryTimeoutIT.java  |   6 +-
 .../iterate/RoundRobinResultIteratorIT.java |  21 +--
 .../RoundRobinResultIteratorWithStatsIT.java|  12 +-
 .../calcite/jdbc/PhoenixCalciteFactory.java |  31 +++-
 .../rel/PhoenixToEnumerableConverter.java   |  13 +-
 .../apache/phoenix/execute/RuntimeContext.java  |  10 +-
 .../phoenix/compile/QueryCompilerTest.java  |  28 ++--
 .../phoenix/compile/QueryOptimizerTest.java | 166 ---
 .../phoenix/filter/SkipScanBigFilterTest.java   |   4 +-
 .../apache/phoenix/util/PhoenixRuntimeTest.java |   5 +-
 .../java/org/apache/phoenix/util/TestUtil.java  |  11 ++
 24 files changed, 211 insertions(+), 208 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/d9caed0a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterMultiTenantTableWithViewsIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterMultiTenantTableWithViewsIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterMultiTenantTableWithViewsIT.java
index 7b4ff68..89df159 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterMultiTenantTableWithViewsIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterMultiTenantTableWithViewsIT.java
@@ -31,7 +31,6 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.ResultSetMetaData;
 import java.sql.SQLException;
-import java.sql.Statement;
 import java.util.List;
 import java.util.Properties;
 
@@ -41,7 +40,6 @@ import org.apache.phoenix.compile.QueryPlan;
 import org.apache.phoenix.exception.SQLExceptionCode;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
-import org.apache.phoenix.jdbc.PhoenixStatement;
 import org.apache.phoenix.schema.ColumnNotFoundException;
 import org.apache.phoenix.schema.PColumn;
 import org.apache.phoenix.schema.PTable;
@@ -50,6 +48,7 @@ import org.apache.phoenix.schema.PTableType;
 import org.apache.phoenix.util.IndexUtil;
 import org.apache.phoenix.util.PhoenixRuntime;
 import org.apache.phoenix.util.SchemaUtil;
+import org.apache.phoenix.util.TestUtil;
 import org.junit.Test;
 
 import com.google.common.base.Objects;
@@ -397,9 +396,8 @@ public class AlterMultiTenantTableWithViewsIT extends 
ParallelStatsDisabledIT {
 String upsert = "UPSERT INTO " + view2 + " (K1, K2, K3, V1, V2, 
V3) VALUES ('key1', 'key2', 'key3', 'value1', 'value2', 'value3')";
 viewConn.createStatement().executeUpdate(upsert);
 viewConn.commit();
-Statement stmt = viewConn.createStatement();
 String sql = "SELECT V2 FROM " + view2 + " WHERE V1 = 'value1' AND 
K3 = 'key3'";
-QueryPlan plan = 
stmt.unwrap(PhoenixStatement.class).optimizeQuery(sql);
+QueryPlan plan = (QueryPlan) TestUtil.getQueryPlan(viewConn, sql);
 
assertTrue(plan.getTableRef().getTable().getName().getString().equals(SchemaUtil.normalizeIdentifier(view2Index)));
 ResultSet rs = viewConn.createStatement().executeQuery(sql);
 verifyNewColumns(rs, "value2");
@@ -463,9 +461,8 @@ public class AlterMultiTenantTableWithViewsIT extends 
ParallelStatsDisabledIT {
 try (Connection viewConn = getTenantConnection("tenant2&qu

[1/2] phoenix git commit: PHOENIX-3785 Replace unwrap(PhoenixStatement.class) with new Calcite-Phoenix statement classes

2017-04-12 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/calcite a78e008b0 -> d9caed0a8


http://git-wip-us.apache.org/repos/asf/phoenix/blob/d9caed0a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java
--
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java 
b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java
index 6c8ac48..9a624be 100644
--- 
a/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/compile/QueryOptimizerTest.java
@@ -37,13 +37,11 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
 
+import 
org.apache.calcite.jdbc.PhoenixCalciteFactory.PhoenixCalcitePreparedStatement;
 import org.apache.hadoop.hbase.client.Scan;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Pair;
 import org.apache.phoenix.compile.OrderByCompiler.OrderBy;
-import org.apache.phoenix.jdbc.PhoenixPreparedStatement;
-import org.apache.phoenix.jdbc.PhoenixResultSet;
-import org.apache.phoenix.jdbc.PhoenixStatement;
 import org.apache.phoenix.query.BaseConnectionlessQueryTest;
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.schema.PColumn;
@@ -74,9 +72,8 @@ public class QueryOptimizerTest extends 
BaseConnectionlessQueryTest {
 Connection conn = DriverManager.getConnection(getUrl());
 conn.createStatement().execute("CREATE TABLE T (k VARCHAR NOT NULL 
PRIMARY KEY, v1 CHAR(15), v2 VARCHAR)");
 conn.createStatement().execute("CREATE INDEX IDX ON T(v1, v2)");
-PhoenixStatement stmt = 
conn.createStatement().unwrap(PhoenixStatement.class);
 String query = "select * from t where (v1, v2, k) > ('1', '2', '3')";
-QueryPlan plan = stmt.optimizeQuery(query);
+QueryPlan plan = (QueryPlan) TestUtil.getQueryPlan(conn, query);
 assertEquals("IDX", 
plan.getTableRef().getTable().getTableName().getString());
 }
 
@@ -84,8 +81,7 @@ public class QueryOptimizerTest extends 
BaseConnectionlessQueryTest {
 public void testOrderByOptimizedOut() throws Exception {
 Connection conn = DriverManager.getConnection(getUrl());
 conn.createStatement().execute("CREATE TABLE foo (k VARCHAR NOT NULL 
PRIMARY KEY, v VARCHAR) IMMUTABLE_ROWS=true");
-PhoenixStatement stmt = 
conn.createStatement().unwrap(PhoenixStatement.class);
-QueryPlan plan = stmt.optimizeQuery("SELECT * FROM foo ORDER BY k");
+QueryPlan plan = (QueryPlan) TestUtil.getQueryPlan(conn, "SELECT * 
FROM foo ORDER BY k");
 assertEquals(OrderBy.FWD_ROW_KEY_ORDER_BY,plan.getOrderBy());
 }
 
@@ -94,8 +90,7 @@ public class QueryOptimizerTest extends 
BaseConnectionlessQueryTest {
 Connection conn = DriverManager.getConnection(getUrl());
 try{ 
 conn.createStatement().execute("CREATE TABLE foo (k VARCHAR NOT 
NULL PRIMARY KEY, v VARCHAR) IMMUTABLE_ROWS=true");
-PhoenixStatement stmt = 
conn.createStatement().unwrap(PhoenixStatement.class);
-QueryPlan plan = stmt.optimizeQuery("SELECT * FROM foo ORDER BY 
'a','b','c'");
+QueryPlan plan = (QueryPlan) TestUtil.getQueryPlan(conn, "SELECT * 
FROM foo ORDER BY 'a','b','c'");
 assertTrue(plan.getOrderBy().getOrderByExpressions().isEmpty());
 } finally {
 conn.close();
@@ -106,8 +101,7 @@ public class QueryOptimizerTest extends 
BaseConnectionlessQueryTest {
 public void testOrderByNotDropped() throws Exception {
 Connection conn = DriverManager.getConnection(getUrl());
 conn.createStatement().execute("CREATE TABLE foo (k VARCHAR NOT NULL 
PRIMARY KEY, v VARCHAR) IMMUTABLE_ROWS=true");
-PhoenixStatement stmt = 
conn.createStatement().unwrap(PhoenixStatement.class);
-QueryPlan plan = stmt.optimizeQuery("SELECT * FROM foo ORDER BY v");
+QueryPlan plan = (QueryPlan) TestUtil.getQueryPlan(conn, "SELECT * 
FROM foo ORDER BY v");
 assertFalse(plan.getOrderBy().getOrderByExpressions().isEmpty());
 }
 
@@ -115,8 +109,7 @@ public class QueryOptimizerTest extends 
BaseConnectionlessQueryTest {
 public void testOrderByDroppedCompositeKey() throws Exception {
 Connection conn = DriverManager.getConnection(getUrl());
 conn.createStatement().execute("CREATE TABLE foo (j INTEGER NOT NULL, 
k BIGINT NOT NULL, v VARCHAR CONSTRAINT pk PRIMARY KEY (j,k)) 
IMMUTABLE_ROWS=true");
-PhoenixStatement stmt = 
conn.createStatement().unwrap(PhoenixStatement.class);
-QueryPlan plan = stmt.optimizeQuery("SELECT * FROM foo ORDER BY j,k");
+QueryPlan plan = (QueryPlan) TestUtil.getQueryPlan(conn, "SELECT * 
FROM foo ORDER BY j,k");
 assertEquals(OrderBy.FWD_ROW_KEY_ORDER_BY,plan.getOrderBy());
 }
 
@@ -124,8 +117,7 @@ public class 

[4/7] phoenix git commit: PHOENIX-3745 SortMergeJoin might incorrectly override the OrderBy of LHS or RHS

2017-04-06 Thread maryannxue
PHOENIX-3745 SortMergeJoin might incorrectly override the OrderBy of LHS or RHS


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

Branch: refs/heads/calcite
Commit: 2c53fc9856ba3770e742c0729cdef9b2c0181873
Parents: 2074d1f
Author: chenglei 
Authored: Fri Mar 31 09:58:35 2017 +0800
Committer: chenglei 
Committed: Fri Mar 31 09:58:35 2017 +0800

--
 .../phoenix/end2end/SortMergeJoinMoreIT.java| 135 +
 .../apache/phoenix/compile/JoinCompiler.java|   6 +-
 .../phoenix/compile/SubselectRewriter.java  | 137 --
 .../phoenix/exception/SQLExceptionCode.java |   1 +
 .../phoenix/execute/DelegateQueryPlan.java  |   4 +
 .../phoenix/execute/SortMergeJoinPlan.java  |   8 +
 .../phoenix/compile/QueryCompilerTest.java  | 187 +++
 7 files changed, 466 insertions(+), 12 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/2c53fc98/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
index 992e55f..e61332b 100644
--- 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SortMergeJoinMoreIT.java
@@ -499,4 +499,139 @@ public class SortMergeJoinMoreIT extends 
ParallelStatsDisabledIT {
 conn.close();
 }
 }
+
+@Test
+public void testSubQueryOrderByOverrideBug3745() throws Exception {
+Connection conn = null;
+try {
+Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+conn = DriverManager.getConnection(getUrl(), props);
+
+String tableName1=generateUniqueName();
+String tableName2=generateUniqueName();
+
+conn.createStatement().execute("DROP TABLE if exists "+tableName1);
+
+String sql="CREATE TABLE IF NOT EXISTS "+tableName1+" ( "+
+"AID INTEGER PRIMARY KEY,"+
+"AGE INTEGER"+
+")";
+conn.createStatement().execute(sql);
+
+conn.createStatement().execute("UPSERT INTO 
"+tableName1+"(AID,AGE) VALUES (1,11)");
+conn.createStatement().execute("UPSERT INTO 
"+tableName1+"(AID,AGE) VALUES (2,22)");
+conn.createStatement().execute("UPSERT INTO 
"+tableName1+"(AID,AGE) VALUES (3,33)");
+conn.commit();
+
+conn.createStatement().execute("DROP TABLE if exists "+tableName2);
+sql="CREATE TABLE IF NOT EXISTS "+tableName2+" ( "+
+"BID INTEGER PRIMARY KEY,"+
+"CODE INTEGER"+
+")";
+conn.createStatement().execute(sql);
+
+conn.createStatement().execute("UPSERT INTO 
"+tableName2+"(BID,CODE) VALUES (1,66)");
+conn.createStatement().execute("UPSERT INTO 
"+tableName2+"(BID,CODE) VALUES (2,55)");
+conn.createStatement().execute("UPSERT INTO 
"+tableName2+"(BID,CODE) VALUES (3,44)");
+conn.commit();
+
+//test for simple scan
+sql="select /*+ USE_SORT_MERGE_JOIN */ a.aid,b.code from (select 
aid,age from "+tableName1+" where age >=11 and age<=33) a inner join "+
+"(select bid,code from "+tableName2+" order by code limit 1) b 
on a.aid=b.bid ";
+
+ResultSet rs=conn.prepareStatement(sql).executeQuery();
+assertTrue(rs.next());
+assertTrue(rs.getInt(1) == 3);
+assertTrue(rs.getInt(2) == 44);
+assertTrue(!rs.next());
+
+sql="select /*+ USE_SORT_MERGE_JOIN */ a.aid,b.code from (select 
aid,age from "+tableName1+" where age >=11 and age<=33) a inner join "+
+"(select bid,code from "+tableName2+" order by code limit 2) b 
on a.aid=b.bid ";
+rs=conn.prepareStatement(sql).executeQuery();
+assertTrue(rs.next());
+assertTrue(rs.getInt(1) == 2);
+assertTrue(rs.getInt(2) == 55);
+assertTrue(rs.next());
+assertTrue(rs.getInt(1) == 3);
+assertTrue(rs.getInt(2) == 44);
+assertTrue(!rs.next());
+
+//test for aggregate
+sql="select /*+ USE_SORT_MERGE_JOIN */ a.aid,b.codesum from 
(select aid,sum(age) agesum from "+tableName1+" where age >=11 and age<=33 
group by aid order by agesum limit 3) a inner join "+
+

[5/7] phoenix git commit: PHOENIX-3756 Handle users lacking ADMIN for the SYSTEM namespace

2017-04-06 Thread maryannxue
PHOENIX-3756 Handle users lacking ADMIN for the SYSTEM namespace


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

Branch: refs/heads/calcite
Commit: 8b3cc71eb9ae5972516435629591dd2ab94df50d
Parents: 2c53fc9
Author: Josh Elser 
Authored: Thu Mar 30 15:13:57 2017 -0400
Committer: Josh Elser 
Committed: Wed Apr 5 17:48:20 2017 -0400

--
 .../end2end/SystemTablePermissionsIT.java   | 263 +++
 .../phoenix/jdbc/PhoenixDatabaseMetaData.java   |   3 +
 .../query/ConnectionQueryServicesImpl.java  |  56 +++-
 .../query/ConnectionQueryServicesImplTest.java  |  73 +
 4 files changed, 383 insertions(+), 12 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/8b3cc71e/phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemTablePermissionsIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemTablePermissionsIT.java
 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemTablePermissionsIT.java
new file mode 100644
index 000..9f213c8
--- /dev/null
+++ 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/SystemTablePermissionsIT.java
@@ -0,0 +1,263 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.end2end;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.security.PrivilegedExceptionAction;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.TableName;
+import org.apache.hadoop.hbase.security.access.AccessControlClient;
+import org.apache.hadoop.hbase.security.access.Permission.Action;
+import org.apache.hadoop.security.UserGroupInformation;
+import org.apache.phoenix.query.QueryServices;
+import org.junit.After;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test that verifies a user can read Phoenix tables with a minimal set of 
permissions.
+ */
+public class SystemTablePermissionsIT {
+private static String SUPERUSER;
+
+private static final Set PHOENIX_SYSTEM_TABLES = new 
HashSet<>(Arrays.asList(
+"SYSTEM.CATALOG", "SYSTEM.SEQUENCE", "SYSTEM.STATS", 
"SYSTEM.FUNCTION",
+"SYSTEM.MUTEX"));
+// PHOENIX- SYSTEM.MUTEX isn't being created in the SYSTEM namespace 
as it should be.
+private static final Set PHOENIX_NAMESPACE_MAPPED_SYSTEM_TABLES = 
new HashSet<>(
+Arrays.asList("SYSTEM:CATALOG", "SYSTEM:SEQUENCE", "SYSTEM:STATS", 
"SYSTEM:FUNCTION",
+"SYSTEM.MUTEX"));
+
+private static final String TABLE_NAME =
+SystemTablePermissionsIT.class.getSimpleName().toUpperCase();
+private static final int NUM_RECORDS = 5;
+
+private HBaseTestingUtility testUtil = null;
+private Properties clientProperties = null;
+
+@BeforeClass
+public static void setup() throws Exception {
+SUPERUSER = System.getProperty("user.name");
+}
+
+private static void setCommonConfigProperties(Configuration conf) {
+conf.set("hbase.coprocessor.master.classes",
+"org.apache.hadoop.hbase.security.access.AccessController");
+conf.set("hbase.coprocessor.region.classes",
+"org.apache.hadoop.hbase.security.access.AccessController");
+conf.set("hbase.coprocessor.regionserver.classes",

[2/7] phoenix git commit: PHOENIX-3693 Upgrade to Tephra 0.11.0

2017-04-06 Thread maryannxue
PHOENIX-3693 Upgrade to Tephra 0.11.0


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

Branch: refs/heads/calcite
Commit: 7050b92435068e95c6f93246a47c76203174
Parents: 8093d10
Author: James Taylor 
Authored: Tue Mar 21 13:34:54 2017 -0700
Committer: James Taylor 
Committed: Tue Mar 21 13:34:54 2017 -0700

--
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/7050b924/pom.xml
--
diff --git a/pom.xml b/pom.xml
index 1b74aa1..248a244 100644
--- a/pom.xml
+++ b/pom.xml
@@ -100,7 +100,7 @@
 2.1.2
 1.9.0
 8.1.7.v20120910
-0.9.0-incubating
+0.11.0-incubating
 2.0.2
 2.11.8
 2.11



[7/7] phoenix git commit: Fix merge conflicts

2017-04-06 Thread maryannxue
Fix merge conflicts


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

Branch: refs/heads/calcite
Commit: 3aecc3d34833c8baf21e5196219079d8d56b1d7e
Parents: d1678c7 92e728e
Author: maryannxue <maryann@gmail.com>
Authored: Thu Apr 6 10:31:59 2017 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Thu Apr 6 10:31:59 2017 -0700

--
 .../apache/phoenix/end2end/AlterTableIT.java|   9 +-
 .../org/apache/phoenix/end2end/ArrayIT.java |   2 +-
 .../phoenix/end2end/AutomaticRebuildIT.java |   4 +-
 .../phoenix/end2end/CoalesceFunctionIT.java |  12 +-
 .../apache/phoenix/end2end/CreateTableIT.java   |   2 +-
 .../end2end/IndexToolForPartialBuildIT.java |   4 +-
 .../phoenix/end2end/NthValueFunctionIT.java |  34 +++
 .../end2end/SequenceBulkAllocationIT.java   |  44 ++--
 .../org/apache/phoenix/end2end/SequenceIT.java  |  44 ++--
 .../phoenix/end2end/SortMergeJoinMoreIT.java| 135 ++
 .../phoenix/end2end/SpillableGroupByIT.java |   2 +-
 .../phoenix/end2end/StatsCollectorIT.java   |  11 +-
 .../phoenix/end2end/StoreNullsPropIT.java   |   2 +-
 .../end2end/SystemTablePermissionsIT.java   | 263 +++
 .../apache/phoenix/end2end/UpsertSelectIT.java  |  18 +-
 .../apache/phoenix/end2end/index/IndexIT.java   |   5 +-
 .../phoenix/end2end/index/IndexMetadataIT.java  |   6 +-
 .../phoenix/end2end/index/IndexTestUtil.java|   2 +-
 .../phoenix/end2end/index/LocalIndexIT.java |   2 +-
 .../org/apache/phoenix/rpc/UpdateCacheIT.java   |   2 +-
 .../phoenix/tx/ParameterizedTransactionIT.java  |   8 +-
 .../apache/phoenix/compile/JoinCompiler.java|   6 +-
 .../phoenix/compile/SubselectRewriter.java  | 137 +-
 .../coprocessor/MetaDataEndpointImpl.java   | 213 +++
 .../phoenix/coprocessor/MetaDataProtocol.java   |   4 +-
 .../phoenix/exception/SQLExceptionCode.java |   1 +
 .../phoenix/execute/DelegateQueryPlan.java  |  10 +-
 .../phoenix/execute/SortMergeJoinPlan.java  |   8 +
 .../FirstLastValueServerAggregator.java |   2 -
 .../phoenix/jdbc/PhoenixDatabaseMetaData.java   |   7 +-
 .../query/ConnectionQueryServicesImpl.java  |  60 -
 .../apache/phoenix/schema/MetaDataClient.java   |  24 +-
 .../java/org/apache/phoenix/schema/PTable.java  |  10 +-
 .../org/apache/phoenix/util/MetaDataUtil.java   |  17 ++
 .../org/apache/phoenix/util/UpgradeUtil.java|  75 +-
 .../phoenix/compile/QueryCompilerTest.java  | 187 +
 .../query/ConnectionQueryServicesImplTest.java  |  73 +
 pom.xml |   2 +-
 38 files changed, 1205 insertions(+), 242 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/3aecc3d3/phoenix-core/src/it/java/org/apache/phoenix/end2end/SequenceIT.java
--

http://git-wip-us.apache.org/repos/asf/phoenix/blob/3aecc3d3/phoenix-core/src/main/java/org/apache/phoenix/execute/DelegateQueryPlan.java
--
diff --cc 
phoenix-core/src/main/java/org/apache/phoenix/execute/DelegateQueryPlan.java
index 4300245,015b8f9..b46a173
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/DelegateQueryPlan.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/DelegateQueryPlan.java
@@@ -132,13 -128,17 +128,17 @@@ public abstract class DelegateQueryPla
  return delegate.getOffset();
  }
   
 - @Override
 - public ResultIterator iterator() throws SQLException {
 - return iterator(DefaultParallelScanGrouper.getInstance());
 - }
 - 
 - @Override
 - public ResultIterator iterator(ParallelScanGrouper scanGrouper) throws 
SQLException {
 - return iterator(scanGrouper, null);
 - }
 +@Override
 +public ResultIterator iterator() throws SQLException {
 +return iterator(DefaultParallelScanGrouper.getInstance());
 +}
-  
++
 +@Override
 +public ResultIterator iterator(ParallelScanGrouper scanGrouper) throws 
SQLException {
 +return iterator(scanGrouper, null);
 +}
+ 
+ public QueryPlan getDelegate() {
+ return delegate;
+ }
 -}
 +}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/3aecc3d3/phoenix-core/src/main/java/org/apache/phoenix/execute/SortMergeJoinPlan.java
--
diff --cc 
phoenix-core/src/main/java/org/apache/phoenix/execute/SortMergeJoinPlan.java
index db6e41a,75bd11c..a6e027f
--- 
a/phoenix-core/src/main/java/org/apache/pho

phoenix git commit: PHOENIX-3768 Fix 'Phoenix schema not found' error

2017-04-05 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/calcite 9ac3aa83e -> d1678c713


PHOENIX-3768 Fix 'Phoenix schema not found' error


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

Branch: refs/heads/calcite
Commit: d1678c7134848742aa3ae11df24d0a335bdae467
Parents: 9ac3aa8
Author: maryannxue <maryann@gmail.com>
Authored: Wed Apr 5 17:31:34 2017 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Wed Apr 5 17:31:34 2017 -0700

--
 .../phoenix/calcite/PhoenixPrepareImpl.java | 23 +-
 .../phoenix/calcite/rel/PhoenixValues.java  | 25 ++--
 2 files changed, 24 insertions(+), 24 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/d1678c71/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java
index c07bd6f..b6d0035 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/PhoenixPrepareImpl.java
@@ -1,6 +1,12 @@
 package org.apache.phoenix.calcite;
 
+import static org.apache.phoenix.util.PhoenixRuntime.CONNECTIONLESS;
+import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL;
+import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR;
+
 import java.lang.reflect.Type;
+import java.sql.Connection;
+import java.sql.DriverManager;
 import java.sql.SQLException;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -115,6 +121,21 @@ import com.google.common.collect.Lists;
 public class PhoenixPrepareImpl extends CalcitePrepareImpl {
 public static final ThreadLocal THREAD_SQL_STRING =
 new ThreadLocal<>();
+
+public static final PhoenixConnection CONNECTIONLESS_PHOENIX_CONNECTION;
+static {
+try {
+Class.forName("org.apache.phoenix.jdbc.PhoenixDriver");
+final Connection connection =
+DriverManager.getConnection(JDBC_PROTOCOL + 
JDBC_PROTOCOL_SEPARATOR + CONNECTIONLESS);
+CONNECTIONLESS_PHOENIX_CONNECTION =
+connection.unwrap(PhoenixConnection.class);
+} catch (ClassNotFoundException e) {
+throw new RuntimeException(e);
+} catch (SQLException e) {
+throw new RuntimeException(e);
+}
+}
 
 protected final RelOptRule[] defaultConverterRules;
 
@@ -718,6 +739,6 @@ public class PhoenixPrepareImpl extends CalcitePrepareImpl {
 } catch (ClassCastException e) {
 }
 }
-throw new RuntimeException("Phoenix schema not found.");
+return CONNECTIONLESS_PHOENIX_CONNECTION;
 }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/d1678c71/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixValues.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixValues.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixValues.java
index 886e861..c979da1 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixValues.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixValues.java
@@ -1,11 +1,5 @@
 package org.apache.phoenix.calcite.rel;
 
-import static org.apache.phoenix.util.PhoenixRuntime.CONNECTIONLESS;
-import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL;
-import static org.apache.phoenix.util.PhoenixRuntime.JDBC_PROTOCOL_SEPARATOR;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
 import java.sql.SQLException;
 import java.util.Iterator;
 import java.util.List;
@@ -28,6 +22,7 @@ import org.apache.calcite.rex.RexLiteral;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.client.Scan;
 import org.apache.phoenix.calcite.CalciteUtils;
+import org.apache.phoenix.calcite.PhoenixPrepareImpl;
 import org.apache.phoenix.calcite.TableMapping;
 import org.apache.phoenix.compile.OrderByCompiler.OrderBy;
 import org.apache.phoenix.compile.ColumnResolver;
@@ -39,7 +34,6 @@ import org.apache.phoenix.compile.StatementContext;
 import org.apache.phoenix.execute.LiteralResultIterationPlan;
 import org.apache.phoenix.execute.TupleProjector;
 import org.apache.phoenix.expression.Expression;
-import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apac

phoenix git commit: PHOENIX-3766 Avoid creating a cast for ROW data type

2017-04-05 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/calcite cca7daaea -> 9ac3aa83e


PHOENIX-3766 Avoid creating a cast for ROW data type


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

Branch: refs/heads/calcite
Commit: 9ac3aa83e32da071ab351c820865d05fc0315ded
Parents: cca7daa
Author: maryannxue <maryann@gmail.com>
Authored: Wed Apr 5 12:54:31 2017 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Wed Apr 5 12:54:57 2017 -0700

--
 .../main/java/org/apache/phoenix/calcite/CalciteUtils.java  | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/9ac3aa83/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java
index 32e89a4..2ab9007 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java
@@ -155,6 +155,7 @@ import org.apache.phoenix.schema.types.PDouble;
 import org.apache.phoenix.schema.types.PLong;
 import org.apache.phoenix.schema.types.PTimestamp;
 import org.apache.phoenix.schema.types.PUnsignedTimestamp;
+import org.apache.phoenix.schema.types.PVarchar;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
@@ -704,6 +705,9 @@ public class CalciteUtils {
public Expression newExpression(RexNode node, 
PhoenixRelImplementor implementor) {
RexLiteral lit = (RexLiteral) node;
 PDataType targetType = relDataTypeToPDataType(node.getType());
+if (targetType == PChar.INSTANCE) {
+targetType = PVarchar.INSTANCE;
+}
Object o = lit.getValue();
if (o instanceof NlsString) {
o = ((NlsString) o).getValue();
@@ -784,7 +788,10 @@ public class CalciteUtils {
 public Expression newExpression(RexNode node,
 PhoenixRelImplementor implementor) {
 List children = convertChildren((RexCall) node, 
implementor);
-PDataType targetType = relDataTypeToPDataType(node.getType());
+RelDataType type = node.getType();
+if (type.getSqlTypeName() == SqlTypeName.ROW)
+return children.get(0);
+PDataType targetType = relDataTypeToPDataType(type);
 Integer maxLength =
 (targetType == PChar.INSTANCE
 || targetType == PCharArray.INSTANCE



phoenix git commit: PHOENIX-3743 Add Row-Value-Constructor support

2017-03-17 Thread maryannxue
Repository: phoenix
Updated Branches:
  refs/heads/calcite db78bd6fd -> cc9115cb0


PHOENIX-3743 Add Row-Value-Constructor support


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

Branch: refs/heads/calcite
Commit: cc9115cb07e35a7f7587a17715e77a12efffe984
Parents: db78bd6
Author: maryannxue <maryann@gmail.com>
Authored: Fri Mar 17 11:11:18 2017 -0700
Committer: maryannxue <maryann@gmail.com>
Committed: Fri Mar 17 11:11:18 2017 -0700

--
 .../org/apache/phoenix/calcite/CalciteUtils.java   | 17 +
 1 file changed, 17 insertions(+)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/cc9115cb/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java
index d37306a..0b098f0 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/CalciteUtils.java
@@ -88,6 +88,7 @@ import org.apache.phoenix.expression.ModulusExpression;
 import org.apache.phoenix.expression.NotExpression;
 import org.apache.phoenix.expression.OrExpression;
 import org.apache.phoenix.expression.ReinterpretCastExpression;
+import org.apache.phoenix.expression.RowValueConstructorExpression;
 import org.apache.phoenix.expression.StringBasedLikeExpression;
 import org.apache.phoenix.expression.TimestampAddExpression;
 import org.apache.phoenix.expression.TimestampSubtractExpression;
@@ -719,6 +720,22 @@ public class CalciteUtils {
}

});
+EXPRESSION_MAP.put(SqlKind.ROW, new ExpressionFactory() {
+
+@Override
+public Expression newExpression(RexNode node, 
PhoenixRelImplementor implementor) {
+List children = convertChildren((RexCall) node, 
implementor);
+boolean isConstant = true;
+for (Expression child : children) {
+if (!child.isStateless()) {
+isConstant = false;
+break;
+}
+}
+return new RowValueConstructorExpression(children, isConstant);
+}
+
+});
EXPRESSION_MAP.put(SqlKind.INPUT_REF, new ExpressionFactory() {
 
@Override



[21/50] [abbrv] phoenix git commit: PHOENIX-3695 Remove testUnfoundSingleColumnCaseStatement from CaseStatementIT

2017-03-16 Thread maryannxue
PHOENIX-3695 Remove testUnfoundSingleColumnCaseStatement from CaseStatementIT


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

Branch: refs/heads/calcite
Commit: 0ea5602f203dc8980125ae75f12989bd793fdf98
Parents: 07b32b9
Author: Samarth 
Authored: Mon Feb 27 14:09:26 2017 -0800
Committer: Samarth 
Committed: Mon Feb 27 14:09:26 2017 -0800

--
 .../org/apache/phoenix/end2end/BaseQueryIT.java | 25 +++---
 .../apache/phoenix/end2end/CaseStatementIT.java | 34 
 2 files changed, 12 insertions(+), 47 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/0ea5602f/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseQueryIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseQueryIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseQueryIT.java
index e82daf9..9a58b5b 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseQueryIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/BaseQueryIT.java
@@ -67,19 +67,18 @@ public abstract class BaseQueryIT extends 
BaseClientManagedTimeIT {
 protected static final long BATCH_SIZE = 3;
 protected static final String[] INDEX_DDLS = new String[] {
 "CREATE INDEX %s ON %s (a_integer DESC) INCLUDE ("
-+ "A_STRING, " + "B_STRING, " + "A_DATE)"};
-//,
-//"CREATE INDEX %s ON %s (a_integer, a_string) INCLUDE ("
-//+ "B_STRING, " + "A_DATE)",
-//"CREATE INDEX %s ON %s (a_integer) INCLUDE ("
-//+ "A_STRING, " + "B_STRING, " + "A_DATE)",
-//"CREATE LOCAL INDEX %s ON %s (a_integer DESC) INCLUDE ("
-//+ "A_STRING, " + "B_STRING, " + "A_DATE)",
-//"CREATE LOCAL INDEX %s ON %s (a_integer, a_string) INCLUDE (" + 
"B_STRING, "
-//+ "A_DATE)",
-//"CREATE LOCAL INDEX %s ON %s (a_integer) INCLUDE ("
-//+ "A_STRING, " + "B_STRING, " + "A_DATE)", 
-//"" };
++ "A_STRING, " + "B_STRING, " + "A_DATE)",
+"CREATE INDEX %s ON %s (a_integer, a_string) INCLUDE ("
++ "B_STRING, " + "A_DATE)",
+"CREATE INDEX %s ON %s (a_integer) INCLUDE ("
++ "A_STRING, " + "B_STRING, " + "A_DATE)",
+"CREATE LOCAL INDEX %s ON %s (a_integer DESC) INCLUDE ("
++ "A_STRING, " + "B_STRING, " + "A_DATE)",
+"CREATE LOCAL INDEX %s ON %s (a_integer, a_string) INCLUDE (" + "  
  B_STRING, "
++ "A_DATE)",
+"CREATE LOCAL INDEX %s ON %s (a_integer) INCLUDE ("
++ "A_STRING, " + "B_STRING, " + "A_DATE)", 
+"" };
 
 @BeforeClass
 @Shadower(classBeingShadowed = BaseClientManagedTimeIT.class)

http://git-wip-us.apache.org/repos/asf/phoenix/blob/0ea5602f/phoenix-core/src/it/java/org/apache/phoenix/end2end/CaseStatementIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CaseStatementIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CaseStatementIT.java
index d2b14a9..31b08db 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CaseStatementIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CaseStatementIT.java
@@ -178,40 +178,6 @@ public class CaseStatementIT extends BaseQueryIT {
 }
 
 @Test
-@Ignore // FIXME:PHOENIX-3695
-public void testUnfoundSingleColumnCaseStatement() throws Exception {
-String query = "SELECT entity_id, b_string FROM " + tableName + " 
WHERE organization_id=? and CASE WHEN a_integer = 0 or a_integer != 0 THEN 1 
ELSE 0 END = 0";
-String url = getUrl() + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" 
+ (ts + 5); // Run query at timestamp 5
-Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
-Connection conn = DriverManager.getConnection(url, props);
-// Set ROW5.A_INTEGER to null so that we have one row
-// where the else clause of the CASE statement will
-// fire.
-url = getUrl() + ";" + PhoenixRuntime.CURRENT_SCN_ATTRIB + "=" + (ts + 
1); // Run query at timestamp 5
-Connection upsertConn = DriverManager.getConnection(url, props);
-String upsertStmt =
-

[27/50] [abbrv] phoenix git commit: PHOENIX-3539 Fix bulkload for StorageScheme - ONE_CELL_PER_KEYVALUE_COLUMN (Samarth Jain and Ankit Singhal)

2017-03-16 Thread maryannxue
PHOENIX-3539 Fix bulkload for StorageScheme - ONE_CELL_PER_KEYVALUE_COLUMN 
(Samarth Jain and Ankit Singhal)


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

Branch: refs/heads/calcite
Commit: 5f5662b24dad478c9cb0917f20e2af9e6a539266
Parents: c387260
Author: Samarth 
Authored: Tue Feb 28 18:00:58 2017 -0800
Committer: Samarth 
Committed: Tue Feb 28 18:00:58 2017 -0800

--
 .../phoenix/end2end/CsvBulkLoadToolIT.java  | 36 ++
 .../mapreduce/FormatToBytesWritableMapper.java  | 51 
 .../mapreduce/FormatToKeyValueReducer.java  | 44 +++--
 .../flume/serializer/CsvEventSerializer.java|  2 +-
 4 files changed, 97 insertions(+), 36 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/phoenix/blob/5f5662b2/phoenix-core/src/it/java/org/apache/phoenix/end2end/CsvBulkLoadToolIT.java
--
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CsvBulkLoadToolIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CsvBulkLoadToolIT.java
index 9103bd8..5a186a0 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CsvBulkLoadToolIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CsvBulkLoadToolIT.java
@@ -372,4 +372,40 @@ public class CsvBulkLoadToolIT extends BaseOwnClusterIT {
 assertTrue(ex instanceof FileAlreadyExistsException); 
 }
 }
+
+@Test
+public void testImportInImmutableTable() throws Exception {
+Statement stmt = conn.createStatement();
+stmt.execute("CREATE IMMUTABLE TABLE S.TABLE10 (ID INTEGER NOT NULL 
PRIMARY KEY, NAME VARCHAR, T DATE, CF1.T2 DATE, CF2.T3 DATE) ");
+
+FileSystem fs = FileSystem.get(getUtility().getConfiguration());
+FSDataOutputStream outputStream = fs.create(new 
Path("/tmp/input10.csv"));
+PrintWriter printWriter = new PrintWriter(outputStream);
+printWriter.println("1,Name 1,1970/01/01,1970/02/01,1970/03/01");
+printWriter.println("2,Name 2,1970/01/02,1970/02/02,1970/03/02");
+printWriter.close();
+CsvBulkLoadTool csvBulkLoadTool = new CsvBulkLoadTool();
+csvBulkLoadTool.setConf(new 
Configuration(getUtility().getConfiguration()));
+csvBulkLoadTool.getConf().set(DATE_FORMAT_ATTRIB, "/MM/dd");
+int exitCode = csvBulkLoadTool.run(new String[] { "--input", 
"/tmp/input10.csv", "--table", "table10",
+"--schema", "s", "--zookeeper", zkQuorum });
+assertEquals(0, exitCode);
+ResultSet rs = stmt.executeQuery("SELECT id, name, t, CF1.T2, CF2.T3 
FROM s.table10 ORDER BY id");
+assertTrue(rs.next());
+assertEquals(1, rs.getInt(1));
+assertEquals("Name 1", rs.getString(2));
+assertEquals(DateUtil.parseDate("1970-01-01"), rs.getDate(3));
+assertEquals(DateUtil.parseDate("1970-02-01"), rs.getDate(4));
+assertEquals(DateUtil.parseDate("1970-03-01"), rs.getDate(5));
+assertTrue(rs.next());
+assertEquals(2, rs.getInt(1));
+assertEquals("Name 2", rs.getString(2));
+assertEquals(DateUtil.parseDate("1970-01-02"), rs.getDate(3));
+assertEquals(DateUtil.parseDate("1970-02-02"), rs.getDate(4));
+assertEquals(DateUtil.parseDate("1970-03-02"), rs.getDate(5));
+assertFalse(rs.next());
+
+rs.close();
+stmt.close();
+}
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/5f5662b2/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java
--
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java
index 278489d..1dae981 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/mapreduce/FormatToBytesWritableMapper.java
@@ -47,7 +47,9 @@ import 
org.apache.phoenix.mapreduce.bulkload.TargetTableRefFunctions;
 import org.apache.phoenix.mapreduce.util.PhoenixConfigurationUtil;
 import org.apache.phoenix.query.QueryConstants;
 import org.apache.phoenix.schema.PColumn;
+import org.apache.phoenix.schema.PColumnFamily;
 import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.schema.PTable.ImmutableStorageScheme;
 import org.apache.phoenix.util.ColumnInfo;
 import org.apache.phoenix.util.EncodedColumnsUtil;
 import 

  1   2   3   4   5   6   7   8   9   10   >