phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maryann...@apache.org
Subject phoenix git commit: Add test cases for View+Correlate; Bug fix in PhoenixServerJoin
Date Wed, 16 Sep 2015 15:38:13 GMT
Repository: phoenix
Updated Branches:
  refs/heads/calcite a8648f12d -> c2cf12642


Add test cases for View+Correlate; Bug fix in PhoenixServerJoin


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

Branch: refs/heads/calcite
Commit: c2cf126428fb379c32ef92d168e4329d54baea7c
Parents: a8648f1
Author: maryannxue <wei.xue@intel.com>
Authored: Wed Sep 16 11:37:56 2015 -0400
Committer: maryannxue <wei.xue@intel.com>
Committed: Wed Sep 16 11:37:56 2015 -0400

----------------------------------------------------------------------
 .../org/apache/phoenix/calcite/CalciteIT.java   | 28 ++++++++++++++++++++
 .../calcite/rel/PhoenixAbstractJoin.java        | 19 +++++++------
 .../phoenix/calcite/rel/PhoenixServerJoin.java  | 16 +++++++++--
 3 files changed, 53 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/c2cf1264/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIT.java b/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIT.java
index b4f187f..7b6b988 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/calcite/CalciteIT.java
@@ -1278,6 +1278,34 @@ public class CalciteIT extends BaseClientManagedTimeIT {
                 "                          PhoenixTableScan(table=[[phoenix, Join, OrderTable]])\n";
         start(correlProps).sql(q5).explainIs(p5Correlate).resultIs(r5).close();
         start(decorrelProps).sql(q5).explainIs(p5Decorrelated).resultIs(r5).close();
+        
+        String q6 = "select organization_id, entity_id, a_integer from v v1 where a_integer
= (select min(a_integer) from v v2 where v1.organization_id = v2.organization_id and v1.b_string
= v2.b_string)";
+        Object[][] r6 = new Object[][] {
+                {"00D300000000XHP", "00A123122312312", 1}, 
+                {"00D300000000XHP", "00A223122312312", 2}, 
+                {"00D300000000XHP", "00A323122312312", 3}};
+        String p6Correlate = 
+                "PhoenixToEnumerableConverter\n" +
+                "  PhoenixClientProject(ORGANIZATION_ID=[$0], ENTITY_ID=[$1], A_INTEGER=[$4])\n"
+
+                "    PhoenixFilter(condition=[=($4, $18)])\n" +
+                "      PhoenixCorrelate(correlation=[$cor0], joinType=[LEFT], requiredColumns=[{0,
3}])\n" +
+                "        PhoenixToClientConverter\n" +
+                "          PhoenixTableScan(table=[[phoenix, ATABLE]], filter=[=($2, 'a')])\n"
+
+                "        PhoenixServerAggregate(group=[{}], EXPR$0=[MIN($4)])\n" +
+                "          PhoenixTableScan(table=[[phoenix, ATABLE]], filter=[AND(=($2,
'a'), =($cor0.ORGANIZATION_ID, $0), =($cor0.B_STRING, $3))])\n";
+        String p6Decorrelated = 
+                "PhoenixToEnumerableConverter\n" +
+                "  PhoenixClientProject(ORGANIZATION_ID=[$0], ENTITY_ID=[$1], A_INTEGER=[$4])\n"
+
+                "    PhoenixToClientConverter\n" +
+                "      PhoenixServerJoin(condition=[AND(=($0, $18), =($3, $19), =($4, $20))],
joinType=[inner])\n" +
+                "        PhoenixTableScan(table=[[phoenix, ATABLE]], filter=[=($2, 'a')])\n"
+
+                "        PhoenixServerAggregate(group=[{18, 19}], EXPR$0=[MIN($4)])\n" +
+                "          PhoenixServerJoin(condition=[AND(=($18, $0), =($19, $3))], joinType=[inner])\n"
+
+                "            PhoenixTableScan(table=[[phoenix, ATABLE]], filter=[=($2, 'a')])\n"
+
+                "            PhoenixServerAggregate(group=[{0, 3}])\n" +
+                "              PhoenixTableScan(table=[[phoenix, ATABLE]], filter=[=($2,
'a')])\n";
+        start(correlProps).sql(q6).explainIs(p6Correlate).resultIs(r6).close();
+        start(decorrelProps).sql(q6).explainIs(p6Decorrelated).resultIs(r6).close();
     }
     
     @Test public void testSelectFromView() {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/c2cf1264/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixAbstractJoin.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixAbstractJoin.java
b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixAbstractJoin.java
index 5d27758..86bc6f9 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixAbstractJoin.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/calcite/rel/PhoenixAbstractJoin.java
@@ -52,16 +52,19 @@ abstract public class PhoenixAbstractJoin extends Join implements PhoenixRel
{
         assert index <= 1;
         
         PhoenixRel input = index == 0 ? (PhoenixRel) left : (PhoenixRel) right;
-        ImmutableIntList keys = index == 0 ? joinInfo.leftKeys : joinInfo.rightKeys;
         QueryPlan plan = implementor.visitInput(0, input);
-        for (Iterator<Integer> iter = keys.iterator(); iter.hasNext();) {
-            Integer i = iter.next();
-            conditionExprs.add(implementor.newColumnExpression(i));
-        }
-        if (conditionExprs.isEmpty()) {
-            conditionExprs.add(LiteralExpression.newConstant(0));
+        
+        if (conditionExprs != null) {
+            ImmutableIntList keys = index == 0 ? joinInfo.leftKeys : joinInfo.rightKeys;
+            for (Iterator<Integer> iter = keys.iterator(); iter.hasNext();) {
+                Integer i = iter.next();
+                conditionExprs.add(implementor.newColumnExpression(i));
+            }
+            if (conditionExprs.isEmpty()) {
+                conditionExprs.add(LiteralExpression.newConstant(0));
+            }
         }
-
+        
         return plan;
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/c2cf1264/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 d9749e0..5419374 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
@@ -1,6 +1,7 @@
 package org.apache.phoenix.calcite.rel;
 
 import java.sql.SQLException;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
 
@@ -21,10 +22,11 @@ import org.apache.phoenix.compile.JoinCompiler;
 import org.apache.phoenix.compile.QueryPlan;
 import org.apache.phoenix.execute.HashJoinPlan;
 import org.apache.phoenix.expression.Expression;
+import org.apache.phoenix.expression.LiteralExpression;
 import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
 import org.apache.phoenix.join.HashJoinInfo;
-import org.apache.phoenix.parse.SelectStatement;
 import org.apache.phoenix.parse.JoinTableNode.JoinType;
+import org.apache.phoenix.parse.SelectStatement;
 import org.apache.phoenix.schema.PTable;
 import org.apache.phoenix.schema.TableRef;
 
@@ -105,7 +107,7 @@ public class PhoenixServerJoin extends PhoenixAbstractJoin {
         List<Expression> rightExprs = Lists.<Expression> newArrayList();
 
         implementor.pushContext(new ImplementorContext(implementor.getCurrentContext().retainPKColumns,
true, getColumnRefList(0)));
-        QueryPlan leftPlan = implementInput(implementor, 0, leftExprs);
+        QueryPlan leftPlan = implementInput(implementor, 0, null);
         PTable leftTable = implementor.getTableRef().getTable();
         implementor.popContext();
 
@@ -122,6 +124,16 @@ public class PhoenixServerJoin extends PhoenixAbstractJoin {
             throw new RuntimeException(e);
         }
         implementor.setTableRef(new TableRef(joinedTable));
+        
+        // Compile left conditions against the joined table due to implementation of HashJoinRegionScanner.
+        for (Iterator<Integer> iter = joinInfo.leftKeys.iterator(); iter.hasNext();)
{
+            Integer i = iter.next();
+            leftExprs.add(implementor.newColumnExpression(i));
+        }
+        if (leftExprs.isEmpty()) {
+            leftExprs.add(LiteralExpression.newConstant(0));
+        }
+
         RexNode postFilter = joinInfo.getRemaining(getCluster().getRexBuilder());
         Expression postFilterExpr = postFilter.isAlwaysTrue() ? null : CalciteUtils.toExpression(postFilter,
implementor);
         @SuppressWarnings("unchecked")


Mime
View raw message