[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 
Authored: Fri Feb 16 11:29:25 2018 -0800
Committer: maryannxue 
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> 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.emptyMap());
 TableRef table = plan.getTableRef();
 if (groupByTableRef != null && !groupByTableRef.equals(table)) {
 groupByTableRef = null;
@@ -1236,7 +1237,8 @@ public class JoinCompiler {
 }
 }
 
-final Map replacement = new HashMap();
+Map replacementMap = null;
+Map 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 (!newTableRef.equals(tableRef)) {
+if (replacementMap == null) {
+  

[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 
Authored: Tue Mar 13 17:02:01 2018 -0700
Committer: maryannxue 
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 
Authored: Fri Feb 16 11:29:25 2018 -0800
Committer: maryannxue 
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> 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.emptyMap());
 TableRef table = plan.getTableRef();
 if (groupByTableRef != null && !groupByTableRef.equals(table)) {
 groupByTableRef = null;
@@ -1236,7 +1237,8 @@ public class JoinCompiler {
 }
 }
 
-final Map replacement = new HashMap();
+Map replacementMap = null;
+Map 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 (!newTableRef.equals(tableRef)) {
+if (replacementMap == null) {
+   

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 
Authored: Fri Feb 16 11:29:25 2018 -0800
Committer: maryannxue 
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> 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.emptyMap());
 TableRef table = plan.getTableRef();
 if (groupByTableRef != null && !groupByTableRef.equals(table)) {
 groupByTableRef = null;
@@ -1236,7 +1237,8 @@ public class JoinCompiler {
 }
 }
 
-final Map replacement = new HashMap();
+Map replacementMap = null;
+Map 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 

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

2018-02-17 Thread pboado
Repository: phoenix
Updated Branches:
  refs/heads/4.x-cdh5.11.2 65f82a9d3 -> 556b05443


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

Branch: refs/heads/4.x-cdh5.11.2
Commit: 4d1954e98bb3e971fec4cf857015a98b04fd9807
Parents: 65f82a9
Author: maryannxue 
Authored: Fri Feb 16 19:50:23 2018 +
Committer: Pedro Boado 
Committed: Sat Feb 17 14:17:14 2018 +

--
 .../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/4d1954e9/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> 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.emptyMap());
 TableRef table = plan.getTableRef();
 if (groupByTableRef != null && !groupByTableRef.equals(table)) {
 groupByTableRef = null;
@@ -1236,7 +1237,8 @@ public class JoinCompiler {
 }
 }
 
-final Map replacement = new HashMap();
+Map replacementMap = null;
+Map 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 

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 
Authored: Fri Feb 16 11:50:23 2018 -0800
Committer: maryannxue 
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> 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.emptyMap());
 TableRef table = plan.getTableRef();
 if (groupByTableRef != null && !groupByTableRef.equals(table)) {
 groupByTableRef = null;
@@ -1236,7 +1237,8 @@ public class JoinCompiler {
 }
 }
 
-final Map replacement = new HashMap();
+Map replacementMap = null;
+Map 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 

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 
Authored: Fri Feb 16 11:45:37 2018 -0800
Committer: maryannxue 
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> 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.emptyMap());
 TableRef table = plan.getTableRef();
 if (groupByTableRef != null && !groupByTableRef.equals(table)) {
 groupByTableRef = null;
@@ -1236,7 +1237,8 @@ public class JoinCompiler {
 }
 }
 
-final Map replacement = new HashMap();
+Map replacementMap = null;
+Map 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 

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 
Authored: Fri Feb 16 11:29:25 2018 -0800
Committer: maryannxue 
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> 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.emptyMap());
 TableRef table = plan.getTableRef();
 if (groupByTableRef != null && !groupByTableRef.equals(table)) {
 groupByTableRef = null;
@@ -1236,7 +1237,8 @@ public class JoinCompiler {
 }
 }
 
-final Map replacement = new HashMap();
+Map replacementMap = null;
+Map 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