zabetak commented on code in PR #6316:
URL: https://github.com/apache/hive/pull/6316#discussion_r2834525805
##########
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:
This is very similar to `applyToFieldCollations` it would be nice to see if
we can refactor some of the commons parts together.
--
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]