hsyuan commented on a change in pull request #1959:
URL: https://github.com/apache/calcite/pull/1959#discussion_r419406480



##########
File path: core/src/main/java/org/apache/calcite/rel/RelDistributions.java
##########
@@ -81,6 +77,15 @@ public static RelDistribution of(RelDistribution.Type type, 
ImmutableIntList key
     return RelDistributionTraitDef.INSTANCE.canonize(distribution);
   }
 
+  public static ImmutableIntList normalizeKeys(Collection<? extends Number> 
numbers) {

Review comment:
       Can you change it to private and add a comment?

##########
File path: core/src/main/java/org/apache/calcite/rel/RelDistributions.java
##########
@@ -135,10 +140,16 @@ public RelDistribution apply(Mappings.TargetMapping 
mapping) {
       if (keys.isEmpty()) {
         return this;
       }
-      return getTraitDef().canonize(
-          new RelDistributionImpl(type,
-              ImmutableIntList.copyOf(
-                  Mappings.apply2((Mapping) mapping, keys))));
+      List<Integer> mapList = Mappings.asList(mapping);
+      for (Integer key : keys) {

Review comment:
       Is `int` OK here?

##########
File path: core/src/main/java/org/apache/calcite/rel/RelDistributions.java
##########
@@ -135,10 +140,16 @@ public RelDistribution apply(Mappings.TargetMapping 
mapping) {
       if (keys.isEmpty()) {
         return this;
       }
-      return getTraitDef().canonize(
-          new RelDistributionImpl(type,
-              ImmutableIntList.copyOf(
-                  Mappings.apply2((Mapping) mapping, keys))));
+      List<Integer> mapList = Mappings.asList(mapping);
+      for (Integer key : keys) {
+        if (mapList.get(key) == null) {
+          return RANDOM_DISTRIBUTED; // Some distribution keys are not mapped 
=> random.
+        }
+      }
+      List<Integer> mappedKeys0 = Mappings.apply2((Mapping) mapping, keys);
+      ImmutableIntList mappedKeys = normalizeKeys(mappedKeys0);
+      RelDistribution newDistribution = new RelDistributionImpl(type, 
mappedKeys);

Review comment:
       Use `of(type, keys)`?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to