gvvinblade commented on a change in pull request #7673: IGNITE-12864: Calcite 
integration. UNION support.
URL: https://github.com/apache/ignite/pull/7673#discussion_r409529543
 
 

 ##########
 File path: 
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/trait/DistributionTrait.java
 ##########
 @@ -139,14 +139,34 @@
 
     /** {@inheritDoc} */
     @Override public IgniteDistribution apply(Mappings.TargetMapping mapping) {
-        if (keys.isEmpty())
+        if (getType() != HASH_DISTRIBUTED)
             return this;
 
-        assert getType() == HASH_DISTRIBUTED;
+        if (mapping.getTargetCount() < keys.size())
+            IgniteDistributions.random();
 
-        ImmutableIntList newKeys = 
IgniteDistributions.projectDistributionKeys(mapping, keys);
+        int[] map = new int[mapping.getSourceCount()];
+        int[] res = new int[keys.size()];
 
-        return newKeys.isEmpty() ? IgniteDistributions.random() : 
IgniteDistributions.hash(newKeys, function);
+        for (int i = 0; i < keys.size(); i++)
+            map[keys.getInt(i)] = i + 1;
+
+        for (int i = 0, found = 0; i < mapping.getTargetCount(); i++) {
+            int source = mapping.getSourceOpt(i);
+            int keyPos = map[source] - 1;
+
+            if (keyPos == -1)
+                continue;
+
+            res[keyPos] = i;
+
+            if (++found == keys.size())
+                return IgniteDistributions.hash(ImmutableIntList.of(res), 
function);
 
 Review comment:
   Actually almost the same, but TargetMapping and Mapping are different 
interfaces

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to