soumyakanti3578 commented on code in PR #6315:
URL: https://github.com/apache/hive/pull/6315#discussion_r2829090719


##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/HiveRelOptUtil.java:
##########
@@ -1107,7 +1107,14 @@ public static List<RelFieldCollation> 
getNewRelFieldCollations(
     Set<Integer> needed = new HashSet<>();
     for (RelFieldCollation fc : sortCollation.getFieldCollations()) {
       needed.add(fc.getFieldIndex());
-      final RexNode node = 
project.getProjects().get(map.getTarget(fc.getFieldIndex()));
+      int target = map.getTargetOpt(fc.getFieldIndex());
+      if (target == -1) {
+        // If there is no mapping for this field, we cannot push down the sort
+        LOG.debug("Missing target mapping for field index: {}. Cannot apply " +
+            "HiveProjectSort[Exchange]TransposeRule", fc.getFieldIndex());

Review Comment:
   Yes, I should remove explicitly naming the rules here. This method is called 
from the `onMatch` methods of the rules and they don't override a `matches` 
method. This results in the rules getting listed as "used" in the logs, as can 
be seen here:
   
   ```
   2026-02-18T16:07:38,518 DEBUG [54732d08-4555-40dd-a149-1347b9af556a main] 
calcite.HiveRelOptUtil: Missing target mapping for field index: 1. Cannot apply 
HiveProjectSort[Exchange]TransposeRule
   2026-02-18T16:07:38,518 DEBUG [54732d08-4555-40dd-a149-1347b9af556a main] 
AbstractRelOptPlanner.rule_execution_summary: Rule Attempts Info for HepPlanner
   2026-02-18T16:07:38,518 DEBUG [54732d08-4555-40dd-a149-1347b9af556a main] 
AbstractRelOptPlanner.rule_execution_summary: 
   Rules                                                                   
Attempts           Time (us)
   HiveCardinalityPreservingJoinRule                                            
  4               8,680
   HiveProjectSearchExpandRule                                                  
  2                  30
   HiveProjectSortExchangeTransposeRule                                         
  1               1,374
   * Total                                                                      
  7              10,084
   
   ```
   
   The ideal solution is to have a `matches` method in the rules but that is 
probably outside of the scope of this ticket. We can do that when we combine 
the two rules into one. But I think I would still like to keep the debug 
message about missing target mapping without naming the rules. What do you 
think @zabetak ?



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