soumyakanti3578 commented on code in PR #6316:
URL: https://github.com/apache/hive/pull/6316#discussion_r2842437280
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HiveSortPullUpConstantsRule.java:
##########
@@ -94,9 +95,24 @@ private HiveSortExchangePullUpConstantsRule() {
@Override
protected void buildSort(RelBuilder relBuilder, HiveSortExchange sortNode,
Mappings.TargetMapping mapping) {
List<RelFieldCollation> fieldCollations =
applyToFieldCollations(sortNode.getCollation(), mapping);
- RelDistribution distribution = sortNode.getDistribution().apply(mapping);
+ RelDistribution distribution =
applyToDistribution(sortNode.getDistribution(), mapping);
relBuilder.sortExchange(distribution, RelCollations.of(fieldCollations));
}
+
+ private RelDistribution applyToDistribution(
+ RelDistribution distribution, Mappings.TargetMapping mapping) {
+ List<Integer> newKeys = new ArrayList<>();
+ for (int key : distribution.getKeys()) {
+ final int target = mapping.getTargetOpt(key);
+ if (target < 0) {
+ // It is a constant, we can ignore it
+ continue;
+ }
+ newKeys.add(target);
+ }
+
+ return new HiveRelDistribution(distribution.getType(), newKeys);
+ }
Review Comment:
I tried moving the for loop which checks if the key is present in the
mapping to a new method. However, this doesn't really simplify
`applyToFieldCollations` as we still need this loop: `for (RelFieldCollation fc
: relCollation.getFieldCollations())`.
Maybe we can revisit this in a follow up.
--
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]