calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [42/50] incubator-calcite git commit: [CALCITE-834] StackOverflowError getting predicates from the metadata provider
Date Wed, 02 Sep 2015 22:16:30 GMT
[CALCITE-834] StackOverflowError getting predicates from the metadata provider


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

Branch: refs/heads/branch-release
Commit: c9d7233d4e2be531814663f2a2ef3fc5600c4950
Parents: a61be0d
Author: Jesus Camacho Rodriguez <jcamacho@apache.org>
Authored: Tue Aug 18 19:57:42 2015 +0300
Committer: Julian Hyde <jhyde@apache.org>
Committed: Tue Aug 18 11:00:33 2015 -0700

----------------------------------------------------------------------
 .../calcite/rel/metadata/RelMdPredicates.java   | 42 ++++++++++++++++----
 .../apache/calcite/test/RelMetadataTest.java    |  2 +-
 2 files changed, 35 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/c9d7233d/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java
index 5e14ba7..1912087 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdPredicates.java
@@ -193,11 +193,21 @@ public class RelMdPredicates {
 
   /** Infers predicates for a {@link org.apache.calcite.rel.core.SemiJoin}. */
   public RelOptPredicateList getPredicates(SemiJoin semiJoin) {
-    final RelNode left = semiJoin.getInput(0);
-    final RelOptPredicateList leftInfo =
+    RexBuilder rB = semiJoin.getCluster().getRexBuilder();
+    RelNode left = semiJoin.getInput(0);
+    RelNode right = semiJoin.getInput(1);
+
+    RelOptPredicateList leftInfo =
         RelMetadataQuery.getPulledUpPredicates(left);
-    return RelOptPredicateList.of(leftInfo.pulledUpPredicates,
-        leftInfo.pulledUpPredicates, ImmutableList.<RexNode>of());
+    RelOptPredicateList rightInfo =
+        RelMetadataQuery.getPulledUpPredicates(right);
+
+    JoinConditionBasedPredicateInference jI =
+        new JoinConditionBasedPredicateInference(semiJoin,
+            RexUtil.composeConjunction(rB, leftInfo.pulledUpPredicates, false),
+            RexUtil.composeConjunction(rB, rightInfo.pulledUpPredicates, false));
+
+    return jI.inferPredicates(false);
   }
 
   /** Infers predicates for a {@link org.apache.calcite.rel.core.Join}. */
@@ -325,6 +335,7 @@ public class RelMdPredicates {
    */
   static class JoinConditionBasedPredicateInference {
     final Join joinRel;
+    final boolean isSemiJoin;
     final int nSysFields;
     final int nFieldsLeft;
     final int nFieldsRight;
@@ -339,9 +350,15 @@ public class RelMdPredicates {
     final RexNode rightChildPredicates;
 
     public JoinConditionBasedPredicateInference(Join joinRel,
+            RexNode lPreds, RexNode rPreds) {
+      this(joinRel, joinRel instanceof SemiJoin, lPreds, rPreds);
+    }
+
+    private JoinConditionBasedPredicateInference(Join joinRel, boolean isSemiJoin,
         RexNode lPreds, RexNode rPreds) {
       super();
       this.joinRel = joinRel;
+      this.isSemiJoin = isSemiJoin;
       nFieldsLeft = joinRel.getLeft().getRowType().getFieldList().size();
       nFieldsRight = joinRel.getRight().getRowType().getFieldList().size();
       nSysFields = joinRel.getSystemFieldList().size();
@@ -453,6 +470,7 @@ public class RelMdPredicates {
           nSysFields + nFieldsLeft, 0, nSysFields, nFieldsLeft);
       final RexPermuteInputsShuttle leftPermute =
           new RexPermuteInputsShuttle(leftMapping, joinRel);
+
       List<RexNode> leftInferredPredicates = new ArrayList<RexNode>();
       List<RexNode> rightInferredPredicates = new ArrayList<RexNode>();
 
@@ -467,12 +485,20 @@ public class RelMdPredicates {
 
       switch (joinType) {
       case INNER:
-        return RelOptPredicateList.of(
-            Iterables.concat(RelOptUtil.conjunctions(leftChildPredicates),
+        Iterable<RexNode> pulledUpPredicates;
+        if (isSemiJoin) {
+          pulledUpPredicates = Iterables.concat(
+                RelOptUtil.conjunctions(leftChildPredicates),
+                leftInferredPredicates);
+        } else {
+          pulledUpPredicates = Iterables.concat(
+                RelOptUtil.conjunctions(leftChildPredicates),
                 RelOptUtil.conjunctions(rightChildPredicates),
                 RelOptUtil.conjunctions(joinRel.getCondition()),
-                inferredPredicates),
-            leftInferredPredicates, rightInferredPredicates);
+                inferredPredicates);
+        }
+        return RelOptPredicateList.of(pulledUpPredicates,
+          leftInferredPredicates, rightInferredPredicates);
       case LEFT:
         return RelOptPredicateList.of(
             RelOptUtil.conjunctions(leftChildPredicates),

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/c9d7233d/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
index ddb116f..5ade0c8 100644
--- a/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
+++ b/core/src/test/java/org/apache/calcite/test/RelMetadataTest.java
@@ -1074,7 +1074,7 @@ public class RelMetadataTest extends SqlToRelTestBase {
 
     predicates = RelMetadataQuery.getPulledUpPredicates(semiJoin);
     assertThat(predicates.pulledUpPredicates.toString(), is("[=($0, 1)]"));
-    assertThat(predicates.leftInferredPredicates.toString(), is("[=($0, 1)]"));
+    assertThat(predicates.leftInferredPredicates.toString(), is("[]"));
     assertThat(predicates.rightInferredPredicates.isEmpty(), is(true));
   }
 


Mime
View raw message