You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ma...@apache.org on 2015/08/13 06:06:46 UTC

phoenix git commit: Bug fixes and code update based on latest Calcite master branch

Repository: phoenix
Updated Branches:
  refs/heads/calcite 39dff45c3 -> 07739579a


Bug fixes and code update based on latest Calcite master branch


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

Branch: refs/heads/calcite
Commit: 07739579a09a3efec0716f8bc6ac5ad205308d49
Parents: 39dff45
Author: maryannxue <we...@intel.com>
Authored: Thu Aug 13 00:06:37 2015 -0400
Committer: maryannxue <we...@intel.com>
Committed: Thu Aug 13 00:06:37 2015 -0400

----------------------------------------------------------------------
 .../org/apache/phoenix/calcite/CalciteTest.java | 44 +++++++++++++-------
 .../apache/phoenix/calcite/PhoenixSchema.java   |  2 +-
 .../phoenix/calcite/rel/PhoenixServerJoin.java  |  3 +-
 .../LiteralResultIterationQueryPlan.java        |  5 ++-
 4 files changed, 35 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/07739579/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 1d11c20..bc6ce70 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
@@ -542,9 +542,9 @@ public class CalciteTest extends BaseClientManagedTimeIT {
         
         start().sql("select s.name, count(\"item_id\") from " + JOIN_SUPPLIER_TABLE_FULL_NAME + " s join " + JOIN_ITEM_TABLE_FULL_NAME + " i on s.\"supplier_id\" = i.\"supplier_id\" group by s.name")
                 .explainIs("PhoenixToEnumerableConverter\n" +
-                           "  PhoenixServerAggregate(group=[{2}], EXPR$1=[COUNT()])\n" +
-                           "    PhoenixServerJoin(condition=[=($1, $0)], joinType=[inner])\n" +
-                           "      PhoenixServerProject(supplier_id=[$5])\n" +
+                           "  PhoenixServerAggregate(group=[{3}], EXPR$1=[COUNT()])\n" +
+                           "    PhoenixServerJoin(condition=[=($2, $1)], joinType=[inner])\n" +
+                           "      PhoenixServerProject(item_id=[$0], supplier_id=[$5])\n" +
                            "        PhoenixTableScan(table=[[phoenix, Join, ItemTable]])\n" +
                            "      PhoenixToClientConverter\n" +
                            "        PhoenixServerProject(supplier_id=[$0], NAME=[$1])\n" +
@@ -619,9 +619,9 @@ public class CalciteTest extends BaseClientManagedTimeIT {
         start().sql("select s.name, count(\"item_id\") from " + JOIN_SUPPLIER_TABLE_FULL_NAME + " s join " + JOIN_ITEM_TABLE_FULL_NAME + " i on s.\"supplier_id\" = i.\"supplier_id\" group by s.name order by count(\"item_id\"), s.name desc")
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixCompactClientSort(sort0=[$1], sort1=[$0], dir0=[ASC], dir1=[DESC])\n" +
-                           "    PhoenixServerAggregate(group=[{2}], EXPR$1=[COUNT()])\n" +
-                           "      PhoenixServerJoin(condition=[=($1, $0)], joinType=[inner])\n" +
-                           "        PhoenixServerProject(supplier_id=[$5])\n" +
+                           "    PhoenixServerAggregate(group=[{3}], EXPR$1=[COUNT()])\n" +
+                           "      PhoenixServerJoin(condition=[=($2, $1)], joinType=[inner])\n" +
+                           "        PhoenixServerProject(item_id=[$0], supplier_id=[$5])\n" +
                            "          PhoenixTableScan(table=[[phoenix, Join, ItemTable]])\n" +
                            "        PhoenixToClientConverter\n" +
                            "          PhoenixServerProject(supplier_id=[$0], NAME=[$1])\n" +
@@ -698,9 +698,9 @@ public class CalciteTest extends BaseClientManagedTimeIT {
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixLimit(fetch=[3])\n" +
                            "    PhoenixCompactClientSort(sort0=[$1], sort1=[$0], dir0=[ASC], dir1=[DESC])\n" +
-                           "      PhoenixServerAggregate(group=[{2}], EXPR$1=[COUNT()])\n" +
-                           "        PhoenixServerJoin(condition=[=($1, $0)], joinType=[inner])\n" +
-                           "          PhoenixServerProject(supplier_id=[$5])\n" +
+                           "      PhoenixServerAggregate(group=[{3}], EXPR$1=[COUNT()])\n" +
+                           "        PhoenixServerJoin(condition=[=($2, $1)], joinType=[inner])\n" +
+                           "          PhoenixServerProject(item_id=[$0], supplier_id=[$5])\n" +
                            "            PhoenixTableScan(table=[[phoenix, Join, ItemTable]])\n" +
                            "          PhoenixToClientConverter\n" +
                            "            PhoenixServerProject(supplier_id=[$0], NAME=[$1])\n" +
@@ -758,9 +758,9 @@ public class CalciteTest extends BaseClientManagedTimeIT {
         start().sql("select s.name, count(\"item_id\") from " + JOIN_SUPPLIER_TABLE_FULL_NAME + " s join " + JOIN_ITEM_TABLE_FULL_NAME + " i on s.\"supplier_id\" = i.\"supplier_id\" group by s.name limit 3")
                 .explainIs("PhoenixToEnumerableConverter\n" +
                            "  PhoenixLimit(fetch=[3])\n" +
-                           "    PhoenixServerAggregate(group=[{2}], EXPR$1=[COUNT()])\n" +
-                           "      PhoenixServerJoin(condition=[=($1, $0)], joinType=[inner])\n" +
-                           "        PhoenixServerProject(supplier_id=[$5])\n" +
+                           "    PhoenixServerAggregate(group=[{3}], EXPR$1=[COUNT()])\n" +
+                           "      PhoenixServerJoin(condition=[=($2, $1)], joinType=[inner])\n" +
+                           "        PhoenixServerProject(item_id=[$0], supplier_id=[$5])\n" +
                            "          PhoenixTableScan(table=[[phoenix, Join, ItemTable]])\n" +
                            "        PhoenixToClientConverter\n" +
                            "          PhoenixServerProject(supplier_id=[$0], NAME=[$1])\n" +
@@ -859,6 +859,12 @@ public class CalciteTest extends BaseClientManagedTimeIT {
     
     @Test public void testIndex() {
         final Start start = start(getConnectionProps(true), false);
+        start.sql("select * from aTable where b_string = 'b'")
+            .explainIs("PhoenixToEnumerableConverter\n" +
+                   "  PhoenixToClientConverter\n" +
+                   "    PhoenixServerProject(ORGANIZATION_ID=[$1], ENTITY_ID=[$2], A_STRING=[$3], B_STRING=[$0], A_INTEGER=[$4], A_DATE=[$5], A_TIME=[$6], A_TIMESTAMP=[$7], X_DECIMAL=[$8], X_LONG=[$9], X_INTEGER=[$10], Y_INTEGER=[$11], A_BYTE=[$12], A_SHORT=[$13], A_FLOAT=[$14], A_DOUBLE=[$15], A_UNSIGNED_FLOAT=[$16], A_UNSIGNED_DOUBLE=[$17])\n" +
+                   "      PhoenixTableScan(table=[[phoenix, IDX_FULL]], filter=[=($0, 'b')])\n")
+            .close();
         start.sql("select x_integer from aTable")
             .explainIs("PhoenixToEnumerableConverter\n" +
                        "  PhoenixToClientConverter\n" +
@@ -879,9 +885,9 @@ public class CalciteTest extends BaseClientManagedTimeIT {
             .close();
         start.sql("select a_integer from aTable order by a_string")
             .explainIs("PhoenixToEnumerableConverter\n" +
-                       "  PhoenixClientProject(A_INTEGER=[$1])\n" +
-                       "    PhoenixServerSort(sort0=[$0], dir0=[ASC])\n" +
-                       "      PhoenixServerProject(A_STRING=[$2], A_INTEGER=[$4])\n" +
+                       "  PhoenixClientProject(A_INTEGER=[$0])\n" +
+                       "    PhoenixServerSort(sort0=[$1], dir0=[ASC])\n" +
+                       "      PhoenixServerProject(A_INTEGER=[$4], A_STRING=[$2])\n" +
                        "        PhoenixTableScan(table=[[phoenix, ATABLE]])\n")
             .close();
         start.sql("select a_string, b_string from aTable where a_string = 'a'")
@@ -904,6 +910,14 @@ public class CalciteTest extends BaseClientManagedTimeIT {
             .close();
     }
     
+    @Test public void testValues() {
+        start().sql("select p0+p1 from (values (2, 1)) as t(p0, p1)")
+            .explainIs("PhoenixToEnumerableConverter\n" +
+                       "  PhoenixClientProject(EXPR$0=[+($0, $1)])\n" +
+                       "    PhoenixValues(tuples=[[{ 2, 1 }]])\n")
+            .close();
+    }
+    
     @Test public void testConnectJoinHsqldb() {
         final Start start = new Start(new Properties(), false) {
             @Override

http://git-wip-us.apache.org/repos/asf/phoenix/blob/07739579/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 d484e01..aee1cb7 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
@@ -191,7 +191,7 @@ public class PhoenixSchema implements Schema {
         sb.setCharAt(6, ' '); // replace first comma with space.
         sb.append(" FROM ").append("\"").append(table.getTableName().getString()).append("\"");
         MaterializationService.instance().defineMaterialization(
-                calciteSchema, null, sb.toString(), path, index.getTableName().getString(), true);        
+                calciteSchema, null, sb.toString(), path, index.getTableName().getString(), true, true);        
     }
 
     /** Schema factory that creates a

http://git-wip-us.apache.org/repos/asf/phoenix/blob/07739579/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerJoin.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerJoin.java b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerJoin.java
index b6a3e1c..1935251 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerJoin.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixServerJoin.java
@@ -74,8 +74,7 @@ public class PhoenixServerJoin extends PhoenixAbstractJoin {
                 || getRight().getConvention() != PhoenixRel.CLIENT_CONVENTION)
             return planner.getCostFactory().makeInfiniteCost();            
         
-        if (joinType == JoinRelType.FULL || joinType == JoinRelType.RIGHT
-                || getLeft().getConvention() != PhoenixRel.SERVER_CONVENTION)
+        if (joinType == JoinRelType.FULL || joinType == JoinRelType.RIGHT)
             return planner.getCostFactory().makeInfiniteCost();
         
         //TODO return infinite cost if RHS size exceeds memory limit.

http://git-wip-us.apache.org/repos/asf/phoenix/blob/07739579/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 ab0341b..dce9f82 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
@@ -75,6 +75,7 @@ public class LiteralResultIterationQueryPlan extends BaseQueryPlan {
             throws SQLException {
         ResultIterator scanner = new ResultIterator() {
             private boolean closed = false;
+            private int count = 0;
 
             @Override
             public void close() throws SQLException {
@@ -83,7 +84,9 @@ public class LiteralResultIterationQueryPlan extends BaseQueryPlan {
 
             @Override
             public Tuple next() throws SQLException {
-                if (!this.closed && tupleIterator.hasNext()) {
+                if (!this.closed 
+                        && (limit == null || count++ < limit)
+                        && tupleIterator.hasNext()) {
                     return tupleIterator.next();
                 }
                 return null;