[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
 }