Repository: phoenix
Updated Branches:
  refs/heads/calcite f9c661680 -> 1f189de2d


PHOENIX-2167 Add new interface in QueryPlan for pushing down a limit value.


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

Branch: refs/heads/calcite
Commit: 1f189de2dfb14c95b8c14aaedd382c3bff8e3371
Parents: f9c6616
Author: maryannxue <wei....@intel.com>
Authored: Wed Aug 19 22:52:03 2015 -0400
Committer: maryannxue <wei....@intel.com>
Committed: Wed Aug 19 22:52:03 2015 -0400

----------------------------------------------------------------------
 .../org/apache/phoenix/calcite/CalciteTest.java |  8 ++++++
 .../phoenix/calcite/rel/PhoenixLimit.java       |  7 ++---
 .../rel/PhoenixToEnumerableConverter.java       |  4 +++
 .../phoenix/calcite/rel/PhoenixValues.java      |  2 +-
 .../phoenix/compile/ListJarsQueryPlan.java      |  5 ++++
 .../org/apache/phoenix/compile/QueryPlan.java   |  9 +++++++
 .../apache/phoenix/compile/TraceQueryPlan.java  |  5 ++++
 .../apache/phoenix/execute/AggregatePlan.java   | 10 +++++++
 .../phoenix/execute/ClientAggregatePlan.java    | 28 ++++++++++++++++----
 .../apache/phoenix/execute/ClientScanPlan.java  |  9 +++++++
 .../phoenix/execute/DegenerateQueryPlan.java    |  6 +++++
 .../apache/phoenix/execute/HashJoinPlan.java    | 10 +++++++
 .../LiteralResultIterationQueryPlan.java        | 10 +++++++
 .../org/apache/phoenix/execute/ScanPlan.java    | 22 ++++++++++++---
 .../phoenix/execute/SortMergeJoinPlan.java      |  7 +++++
 .../phoenix/execute/TupleProjectionPlan.java    |  9 +++++++
 .../org/apache/phoenix/execute/UnionPlan.java   | 11 +++++++-
 .../apache/phoenix/jdbc/PhoenixStatement.java   |  5 ++++
 .../query/ParallelIteratorsSplitTest.java       |  5 ++++
 19 files changed, 159 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/1f189de2/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteTest.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteTest.java 
b/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteTest.java
index bc6ce70..311926e 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteTest.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteTest.java
@@ -787,6 +787,14 @@ public class CalciteTest extends BaseClientManagedTimeIT {
                           {"0000000002", "T2", "0000000001", "S1"}, 
                           {"0000000003", "T3", "0000000002", "S2"}})
                 .close();
+        
+        start().sql("SELECT x from (values (1, 2), (2, 4), (3, 6)) as t(x, y) 
limit 2")
+                .explainIs("PhoenixToEnumerableConverter\n" +
+                           "  PhoenixClientProject(X=[$0])\n" +
+                           "    PhoenixLimit(fetch=[2])\n" +
+                           "      PhoenixValues(tuples=[[{ 1, 2 }, { 2, 4 }, { 
3, 6 }]])\n")
+                .resultIs(new Object[][] {{1}, {2}})
+                .close();
     }
     
     @Test public void testSubquery() {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1f189de2/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixLimit.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixLimit.java 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixLimit.java
index 55acd4a..ab182b0 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixLimit.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixLimit.java
@@ -90,9 +90,10 @@ public class PhoenixLimit extends SingleRel implements 
PhoenixRel {
     @Override
     public QueryPlan implement(Implementor implementor) {
         QueryPlan plan = implementor.visitInput(0, (PhoenixRel) getInput());
-        // TODO only wrap with ClientScanPlan 
-        // if (plan.getLimit() != null);
-        // otherwise add limit to "plan"
+        if (plan.getLimit() == null) {
+            return plan.limit(statelessFetch);
+        }
+        
         return new ClientScanPlan(plan.getContext(), plan.getStatement(), 
                 implementor.getTableRef(), RowProjector.EMPTY_PROJECTOR, 
                 statelessFetch, null, OrderBy.EMPTY_ORDER_BY, plan);

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1f189de2/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixToEnumerableConverter.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixToEnumerableConverter.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixToEnumerableConverter.java
index 57e5136..e4cd07d 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixToEnumerableConverter.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixToEnumerableConverter.java
@@ -103,6 +103,10 @@ public class PhoenixToEnumerableConverter extends 
ConverterImpl implements Enume
                     throws SQLException {
                 return delegate.iterator(scanGrouper);
             }
+            @Override
+            public QueryPlan limit(Integer limit) {
+                return delegate.limit(limit);
+            }
         };
     }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1f189de2/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 6f5bdc9..c9013e6 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
@@ -78,7 +78,7 @@ public class PhoenixValues extends Values implements 
PhoenixRel {
         List<Tuple> literalResult = Lists.newArrayList();
         Iterator<ImmutableList<RexLiteral>> iter = getTuples().iterator();
         Tuple baseTuple = new SingleKeyValueTuple(KeyValue.LOWESTKEY);
-        if (iter.hasNext()) {
+        while (iter.hasNext()) {
             ImmutableList<RexLiteral> row = iter.next();
             List<Expression> exprs = 
Lists.newArrayListWithExpectedSize(row.size());
             for (RexLiteral rexLiteral : row) {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1f189de2/phoenix-core/src/main/java/org/apache/phoenix/compile/ListJarsQueryPlan.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/ListJarsQueryPlan.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/ListJarsQueryPlan.java
index 9fdf35b..1762466 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/ListJarsQueryPlan.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/ListJarsQueryPlan.java
@@ -213,4 +213,9 @@ public class ListJarsQueryPlan implements QueryPlan {
     public boolean useRoundRobinIterator() {
         return false;
     }
+
+    @Override
+    public QueryPlan limit(Integer limit) {
+        return this;
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1f189de2/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryPlan.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryPlan.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryPlan.java
index 1c0c469..c8d89d5 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/QueryPlan.java
@@ -83,4 +83,13 @@ public interface QueryPlan extends StatementPlan {
      */
     public boolean useRoundRobinIterator() throws SQLException;
     
+    /**
+     * Create a copy of the current QueryPlan with a new limit value.
+     * 
+     * @param  limit the new limit value.
+     * @return the new QueryPlan or the current QueryPlan if the limit 
+     *         value is unchanged or if the limit value does not make a
+     *         difference in the QueryPlan's behavior.
+     */
+    public QueryPlan limit(Integer limit);
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1f189de2/phoenix-core/src/main/java/org/apache/phoenix/compile/TraceQueryPlan.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/TraceQueryPlan.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/TraceQueryPlan.java
index 93a2da0..21f984e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/TraceQueryPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/TraceQueryPlan.java
@@ -238,4 +238,9 @@ public class TraceQueryPlan implements QueryPlan {
     public boolean useRoundRobinIterator() {
         return false;
     }
+
+    @Override
+    public QueryPlan limit(Integer limit) {
+        return this;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1f189de2/phoenix-core/src/main/java/org/apache/phoenix/execute/AggregatePlan.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/AggregatePlan.java 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/AggregatePlan.java
index 33cedef..598ead2 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/AggregatePlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/AggregatePlan.java
@@ -25,6 +25,7 @@ import java.util.List;
 import org.apache.hadoop.hbase.client.Scan;
 import org.apache.phoenix.compile.GroupByCompiler.GroupBy;
 import org.apache.phoenix.compile.OrderByCompiler.OrderBy;
+import org.apache.phoenix.compile.QueryPlan;
 import org.apache.phoenix.compile.RowProjector;
 import org.apache.phoenix.compile.StatementContext;
 import org.apache.phoenix.coprocessor.BaseScannerRegionObserver;
@@ -220,4 +221,13 @@ public class AggregatePlan extends BaseQueryPlan {
     public boolean useRoundRobinIterator() throws SQLException {
         return false;
     }
+
+    @Override
+    public QueryPlan limit(Integer limit) {
+        if (limit == this.limit || (limit != null && limit.equals(this.limit)))
+            return this;
+        
+        return new AggregatePlan(this.context, this.statement, this.tableRef, 
this.projection,
+            limit, this.orderBy, this.parallelIteratorFactory, this.groupBy, 
this.having);
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1f189de2/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 3df0447..0c6319a 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
@@ -68,16 +68,24 @@ public class ClientAggregatePlan extends 
ClientProcessingPlan {
     private final Expression having;
     private final Aggregators serverAggregators;
     private final Aggregators clientAggregators;
-    
+
     public ClientAggregatePlan(StatementContext context, FilterableStatement 
statement, TableRef table, RowProjector projector,
             Integer limit, Expression where, OrderBy orderBy, GroupBy groupBy, 
Expression having, QueryPlan delegate) {
+        this(context, statement, table, projector, limit, where, orderBy, 
groupBy, having, delegate, 
+                ServerAggregators.deserialize(
+                        
context.getScan().getAttribute(BaseScannerRegionObserver.AGGREGATORS), 
+                        
QueryServicesOptions.withDefaults().getConfiguration()), 
+                context.getAggregationManager().getAggregators());
+    }
+    
+    private ClientAggregatePlan(StatementContext context, FilterableStatement 
statement, TableRef table, RowProjector projector,
+            Integer limit, Expression where, OrderBy orderBy, GroupBy groupBy, 
Expression having, QueryPlan delegate,
+            Aggregators serverAggregators, Aggregators clientAggregators) {
         super(context, statement, table, projector, limit, where, orderBy, 
delegate);
         this.groupBy = groupBy;
         this.having = having;
-        this.serverAggregators =
-                ServerAggregators.deserialize(context.getScan()
-                        .getAttribute(BaseScannerRegionObserver.AGGREGATORS), 
QueryServicesOptions.withDefaults().getConfiguration());
-        this.clientAggregators = 
context.getAggregationManager().getAggregators();
+        this.serverAggregators = serverAggregators;
+        this.clientAggregators = clientAggregators;
     }
 
     @Override
@@ -229,4 +237,14 @@ public class ClientAggregatePlan extends 
ClientProcessingPlan {
                     + resultIterator + ", aggregators=" + aggregators + "]";
         }
     }
+
+    @Override
+    public QueryPlan limit(Integer limit) {
+        if (limit == this.limit || (limit != null && limit.equals(this.limit)))
+            return this;
+        
+        return new ClientAggregatePlan(this.context, this.statement, 
this.table, 
+                this.projector, limit, this.where, this.orderBy, this.groupBy, 
this.having, 
+                this.delegate, this.serverAggregators, this.clientAggregators);
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1f189de2/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientScanPlan.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientScanPlan.java 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientScanPlan.java
index 4bf1889..08adcce 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientScanPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/ClientScanPlan.java
@@ -90,4 +90,13 @@ public class ClientScanPlan extends ClientProcessingPlan {
         return new ExplainPlan(planSteps);
     }
 
+    @Override
+    public QueryPlan limit(Integer limit) {
+        if (limit == this.limit || (limit != null && limit.equals(this.limit)))
+            return this;
+        
+        return new ClientScanPlan(this.context, this.statement, this.table,
+                this.projector, limit, this.where, this.orderBy, 
this.delegate);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1f189de2/phoenix-core/src/main/java/org/apache/phoenix/execute/DegenerateQueryPlan.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/DegenerateQueryPlan.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/DegenerateQueryPlan.java
index 98eb2dd..ada4387 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/DegenerateQueryPlan.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/DegenerateQueryPlan.java
@@ -24,6 +24,7 @@ import java.util.List;
 import org.apache.hadoop.hbase.client.Scan;
 import org.apache.phoenix.compile.GroupByCompiler.GroupBy;
 import org.apache.phoenix.compile.OrderByCompiler.OrderBy;
+import org.apache.phoenix.compile.QueryPlan;
 import org.apache.phoenix.compile.RowProjector;
 import org.apache.phoenix.compile.ScanRanges;
 import org.apache.phoenix.compile.StatementContext;
@@ -61,4 +62,9 @@ public class DegenerateQueryPlan extends BaseQueryPlan {
         return false;
     }
 
+    @Override
+    public QueryPlan limit(Integer limit) {
+        return this;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1f189de2/phoenix-core/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java
index ead6ec9..adc1a0e 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/HashJoinPlan.java
@@ -417,6 +417,16 @@ public class HashJoinPlan extends DelegateQueryPlan {
         }
         
     }
+
+    @Override
+    public QueryPlan limit(Integer limit) {
+        QueryPlan delegate = this.delegate.limit(limit);
+        if (delegate == this.delegate)
+            return this;
+
+        return new HashJoinPlan(this.statement, delegate, this.joinInfo, 
+                this.subPlans, this.recompileWhereClause);
+    }
 }
 
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1f189de2/phoenix-core/src/main/java/org/apache/phoenix/execute/LiteralResultIterationQueryPlan.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/LiteralResultIterationQueryPlan.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/LiteralResultIterationQueryPlan.java
index dce9f82..8207594 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/LiteralResultIterationQueryPlan.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/LiteralResultIterationQueryPlan.java
@@ -26,6 +26,7 @@ import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.client.Scan;
 import org.apache.phoenix.compile.GroupByCompiler.GroupBy;
 import org.apache.phoenix.compile.OrderByCompiler.OrderBy;
+import org.apache.phoenix.compile.QueryPlan;
 import org.apache.phoenix.compile.RowProjector;
 import org.apache.phoenix.compile.StatementContext;
 import org.apache.phoenix.iterate.ParallelIteratorFactory;
@@ -105,4 +106,13 @@ public class LiteralResultIterationQueryPlan extends 
BaseQueryPlan {
         return scanner;
     }
 
+    @Override
+    public QueryPlan limit(Integer limit) {
+        if (limit == this.limit || (limit != null && limit.equals(this.limit)))
+            return this;
+        
+        return new LiteralResultIterationQueryPlan(this.tupleIterator, 
this.context, this.statement, this.tableRef, 
+                this.projection, limit, this.orderBy, 
this.parallelIteratorFactory);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1f189de2/phoenix-core/src/main/java/org/apache/phoenix/execute/ScanPlan.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/ScanPlan.java 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/ScanPlan.java
index b6598b6..1e18aa6 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/ScanPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/ScanPlan.java
@@ -18,6 +18,7 @@
 package org.apache.phoenix.execute;
 
 
+import java.sql.ParameterMetaData;
 import java.sql.SQLException;
 import java.util.List;
 
@@ -25,6 +26,7 @@ import org.apache.hadoop.hbase.HTableDescriptor;
 import org.apache.hadoop.hbase.client.Scan;
 import org.apache.phoenix.compile.GroupByCompiler.GroupBy;
 import org.apache.phoenix.compile.OrderByCompiler.OrderBy;
+import org.apache.phoenix.compile.QueryPlan;
 import org.apache.phoenix.compile.RowProjector;
 import org.apache.phoenix.compile.StatementContext;
 import org.apache.phoenix.coprocessor.BaseScannerRegionObserver;
@@ -81,9 +83,14 @@ public class ScanPlan extends BaseQueryPlan {
     }
     
     public ScanPlan(StatementContext context, FilterableStatement statement, 
TableRef table, RowProjector projector, Integer limit, OrderBy orderBy, 
ParallelIteratorFactory parallelIteratorFactory, boolean allowPageFilter) 
throws SQLException {
-        super(context, statement, table, projector, 
context.getBindManager().getParameterMetaData(), limit, orderBy, 
GroupBy.EMPTY_GROUP_BY,
-                parallelIteratorFactory != null ? parallelIteratorFactory :
-                        buildResultIteratorFactory(context, table, orderBy, 
limit, allowPageFilter));
+        this(context, statement, table, projector, 
context.getBindManager().getParameterMetaData(), limit, orderBy, 
+                parallelIteratorFactory != null ? parallelIteratorFactory : 
+                    buildResultIteratorFactory(context, table, orderBy, limit, 
allowPageFilter), 
+                allowPageFilter);
+    }
+    
+    private ScanPlan(StatementContext context, FilterableStatement statement, 
TableRef table, RowProjector projector, ParameterMetaData paramMetaData, 
Integer limit, OrderBy orderBy, ParallelIteratorFactory 
parallelIteratorFactory, boolean allowPageFilter) {
+        super(context, statement, table, projector, paramMetaData, limit, 
orderBy, GroupBy.EMPTY_GROUP_BY, parallelIteratorFactory);
         this.allowPageFilter = allowPageFilter;
         if (!orderBy.getOrderByExpressions().isEmpty()) { // TopN
             int thresholdBytes = 
context.getConnection().getQueryServices().getProps().getInt(
@@ -222,4 +229,13 @@ public class ScanPlan extends BaseQueryPlan {
         return ScanUtil.isRoundRobinPossible(orderBy, context);
     }
 
+    @Override
+    public QueryPlan limit(Integer limit) {
+        if (limit == this.limit || (limit != null && limit.equals(this.limit)))
+            return this;
+        
+        return new ScanPlan(this.context, this.statement, this.tableRef, 
this.projection, 
+                this.paramMetaData, limit, this.orderBy, 
this.parallelIteratorFactory, this.allowPageFilter);
+    }
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1f189de2/phoenix-core/src/main/java/org/apache/phoenix/execute/SortMergeJoinPlan.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/SortMergeJoinPlan.java 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/SortMergeJoinPlan.java
index 1bbda07..f768709 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/SortMergeJoinPlan.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/SortMergeJoinPlan.java
@@ -644,5 +644,12 @@ public class SortMergeJoinPlan implements QueryPlan {
         return false;
     }
 
+    @Override
+    public QueryPlan limit(Integer limit) {
+        // This should never be reached, since SortMergeJoinPlan should always 
be
+        // wrapped inside a ClientProcessingPlan.
+        throw new UnsupportedOperationException();
+    }
+
 }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1f189de2/phoenix-core/src/main/java/org/apache/phoenix/execute/TupleProjectionPlan.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/TupleProjectionPlan.java
 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/TupleProjectionPlan.java
index 5993164..df858d3 100644
--- 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/TupleProjectionPlan.java
+++ 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/TupleProjectionPlan.java
@@ -91,4 +91,13 @@ public class TupleProjectionPlan extends DelegateQueryPlan {
         
         return iterator;
     }
+
+    @Override
+    public QueryPlan limit(Integer limit) {
+        QueryPlan delegate = this.delegate.limit(limit);
+        if (delegate == this.delegate)
+            return this;
+        
+        return new TupleProjectionPlan(delegate, this.tupleProjector, 
this.postFilter);
+    }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1f189de2/phoenix-core/src/main/java/org/apache/phoenix/execute/UnionPlan.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/execute/UnionPlan.java 
b/phoenix-core/src/main/java/org/apache/phoenix/execute/UnionPlan.java
index 53745fe..d80017a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/execute/UnionPlan.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/execute/UnionPlan.java
@@ -59,7 +59,7 @@ public class UnionPlan implements QueryPlan {
     private UnionResultIterators iterators;
 
     public UnionPlan(StatementContext context, FilterableStatement statement, 
TableRef table, RowProjector projector,
-            Integer limit, OrderBy orderBy, GroupBy groupBy, List<QueryPlan> 
plans, ParameterMetaData paramMetaData) throws SQLException {
+            Integer limit, OrderBy orderBy, GroupBy groupBy, List<QueryPlan> 
plans, ParameterMetaData paramMetaData) {
         this.parentContext = context;
         this.statement = statement;
         this.tableRef = table;
@@ -197,5 +197,14 @@ public class UnionPlan implements QueryPlan {
     public boolean useRoundRobinIterator() throws SQLException {
         return false;
     }
+
+    @Override
+    public QueryPlan limit(Integer limit) {
+        if (limit == this.limit || (limit != null && limit.equals(this.limit)))
+            return this;
+        
+        return new UnionPlan(this.parentContext, this.statement, 
this.tableRef, this.projector,
+            limit, this.orderBy, this.groupBy, this.plans, this.paramMetaData);
+    }
 }
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1f189de2/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java 
b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
index 056263a..cc67a47 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/jdbc/PhoenixStatement.java
@@ -530,6 +530,11 @@ public class PhoenixStatement implements Statement, 
SQLCloseable, org.apache.pho
                 public boolean useRoundRobinIterator() throws SQLException {
                     return false;
                 }
+
+                @Override
+                public QueryPlan limit(Integer limit) {
+                    return this;
+                }
                 
             };
         }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/1f189de2/phoenix-core/src/test/java/org/apache/phoenix/query/ParallelIteratorsSplitTest.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/test/java/org/apache/phoenix/query/ParallelIteratorsSplitTest.java
 
b/phoenix-core/src/test/java/org/apache/phoenix/query/ParallelIteratorsSplitTest.java
index ad65373..81b086a 100644
--- 
a/phoenix-core/src/test/java/org/apache/phoenix/query/ParallelIteratorsSplitTest.java
+++ 
b/phoenix-core/src/test/java/org/apache/phoenix/query/ParallelIteratorsSplitTest.java
@@ -437,6 +437,11 @@ public class ParallelIteratorsSplitTest extends 
BaseConnectionlessQueryTest {
             public boolean useRoundRobinIterator() {
                 return false;
             }
+
+            @Override
+            public QueryPlan limit(Integer limit) {
+                return this;
+            }
             
         }, null, new 
SpoolingResultIterator.SpoolingResultIteratorFactory(context.getConnection().getQueryServices()));
         List<KeyRange> keyRanges = parallelIterators.getSplits();

Reply via email to