calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [2/2] incubator-calcite git commit: [CALCITE-608] Exception is thrown when RelMdDistribution for Project operator is called (Jesus Camacho Rodriguez)
Date Tue, 10 Mar 2015 01:12:19 GMT
[CALCITE-608] Exception is thrown when RelMdDistribution for Project operator is called (Jesus
Camacho Rodriguez)

Close apache/incubator-calcite#56


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

Branch: refs/heads/master
Commit: 03e9449837eee214df8131185a80a560dd192660
Parents: ee3347f
Author: Jesus Camacho Rodriguez <jcamachorodriguez@hortonworks.com>
Authored: Sun Mar 8 18:39:07 2015 -0700
Committer: Julian Hyde <jhyde@apache.org>
Committed: Mon Mar 9 17:38:39 2015 -0700

----------------------------------------------------------------------
 .../org/apache/calcite/rel/core/Project.java    | 33 ++++++++++++++++++--
 .../calcite/rel/metadata/RelMdDistribution.java |  3 +-
 2 files changed, 32 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/03e94498/core/src/main/java/org/apache/calcite/rel/core/Project.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/core/Project.java b/core/src/main/java/org/apache/calcite/rel/core/Project.java
index 842c0de..af24c58 100644
--- a/core/src/main/java/org/apache/calcite/rel/core/Project.java
+++ b/core/src/main/java/org/apache/calcite/rel/core/Project.java
@@ -276,13 +276,14 @@ public abstract class Project extends SingleRel {
    *
    * @param inputFieldCount Number of input fields
    * @param projects Project expressions
-   * @return Mapping of a set of project expressions
+   * @return Mapping of a set of project expressions, or null if projection is
+   * not a mapping
    */
   public static Mappings.TargetMapping getMapping(int inputFieldCount,
       List<? extends RexNode> projects) {
     Mappings.TargetMapping mapping =
-        Mappings.create(
-            MappingType.INVERSE_SURJECTION, inputFieldCount, projects.size());
+        Mappings.create(MappingType.INVERSE_SURJECTION,
+            inputFieldCount, projects.size());
     for (Ord<RexNode> exp : Ord.zip(projects)) {
       if (!(exp.e instanceof RexInputRef)) {
         return null;
@@ -293,6 +294,32 @@ public abstract class Project extends SingleRel {
   }
 
   /**
+   * Returns a partial mapping of a set of project expressions.
+   *
+   * <p>The mapping is an inverse function.
+   * Every target has a source field, but
+   * a source might have 0, 1 or more targets.
+   * Project expressions that do not consist of
+   * a mapping are ignored.
+   *
+   * @param inputFieldCount Number of input fields
+   * @param projects Project expressions
+   * @return Mapping of a set of project expressions, never null
+   */
+  public static Mappings.TargetMapping getPartialMapping(int inputFieldCount,
+      List<? extends RexNode> projects) {
+    Mappings.TargetMapping mapping =
+        Mappings.create(MappingType.INVERSE_FUNCTION,
+            inputFieldCount, projects.size());
+    for (Ord<RexNode> exp : Ord.zip(projects)) {
+      if (exp.e instanceof RexInputRef) {
+        mapping.set(((RexInputRef) exp.e).getIndex(), exp.i);
+      }
+    }
+    return mapping;
+  }
+
+  /**
    * Returns a permutation, if this projection is merely a permutation of its
    * input fields; otherwise null.
    *

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/03e94498/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistribution.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistribution.java b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistribution.java
index 086cc64..67ac6a2 100644
--- a/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistribution.java
+++ b/core/src/main/java/org/apache/calcite/rel/metadata/RelMdDistribution.java
@@ -138,7 +138,8 @@ public class RelMdDistribution {
     final RelDistribution inputDistribution =
         RelMetadataQuery.distribution(input);
     final Mappings.TargetMapping mapping =
-        Project.getMapping(input.getRowType().getFieldCount(), projects);
+        Project.getPartialMapping(input.getRowType().getFieldCount(),
+            projects);
     return inputDistribution.apply(mapping);
   }
 


Mime
View raw message