nooneuse commented on code in PR #66307:
URL: https://github.com/apache/doris/pull/66307#discussion_r3703661510


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/LogicalOlapScanToPhysicalOlapScan.java:
##########
@@ -132,12 +140,63 @@ public static DistributionSpec 
convertDistribution(LogicalOlapScan olapScan) {
                         }
                     }
                 }
-                return new DistributionSpecHash(hashColumns, 
ShuffleType.NATURAL, olapScan.getTable().getId(),
-                        olapScan.getSelectedIndexId(), 
Sets.newLinkedHashSet(olapScan.getSelectedPartitionIds()));
+                return createNaturalHashSpec(olapScan, hashDistributionInfo, 
hashColumns, output);
             }
         } else {
             // RandomDistributionInfo
             return DistributionSpecStorageAny.INSTANCE;
         }
     }
+
+    private static DistributionSpecHash createNaturalHashSpec(LogicalOlapScan 
olapScan,
+            HashDistributionInfo hashDistributionInfo, List<ExprId> 
hashColumns, List<Slot> output) {
+        return new DistributionSpecHash(hashColumns, ShuffleType.NATURAL, 
olapScan.getTable().getId(),
+                olapScan.getSelectedIndexId(), 
Sets.newLinkedHashSet(olapScan.getSelectedPartitionIds()),
+                buildDistributionMappings(olapScan.getTable(), 
hashDistributionInfo, output));
+    }
+
+    private static List<DistributionMapping> 
buildDistributionMappings(OlapTable table,
+            HashDistributionInfo hashDistributionInfo, List<Slot> output) {
+        ConnectContext context = ConnectContext.get();
+        if (context == null || 
!context.getSessionVariable().isEnableColocateMappingConstraint()) {
+            return ImmutableList.of();
+        }
+
+        Map<String, ExprId> columnExprIds = new HashMap<>();
+        for (Slot slot : output) {
+            SlotReference slotReference = (SlotReference) slot;
+            slotReference.getOriginalColumn().ifPresent(
+                    column -> 
columnExprIds.put(column.getName().toLowerCase(), slot.getExprId()));

Review Comment:
   I understand your point. The issue does exist, and I will fix it. However, 
your example is actually not valid, because currently it's not possible to 
create this kind of MV — it would just throw an error directly. But I will add 
another test case as a regression test.



-- 
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.

To unsubscribe, e-mail: [email protected]

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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to