PaulJackson123 commented on code in PR #3495:
URL: https://github.com/apache/calcite/pull/3495#discussion_r1406904949
##########
core/src/main/java/org/apache/calcite/rel/metadata/RelMdUniqueKeys.java:
##########
@@ -334,30 +334,23 @@ public Set<ImmutableBitSet> getUniqueKeys(Aggregate rel,
RelMetadataQuery mq,
preciseUniqueKeys = ImmutableSet.of(reducedGroupKeys);
} else {
// Try to find more precise unique keys.
- Set<ImmutableBitSet> keysInGroupBy = inputUniqueKeys.stream()
+ final Set<ImmutableBitSet> keysInGroupBy = inputUniqueKeys.stream()
.filter(reducedGroupKeys::contains).collect(Collectors.toSet());
preciseUniqueKeys = keysInGroupBy.isEmpty()
? ImmutableSet.of(reducedGroupKeys)
: keysInGroupBy;
}
- // If an input's unique column value is returned (passed through) by an
aggregation
- // function, then the result of the function is also unique.
- ImmutableSet.Builder<ImmutableBitSet> keysBuilder =
ImmutableSet.builder();
+ // If an input's unique column(s) value is returned (passed through) by
an aggregation
+ // function, then the result of the function(s) is also unique.
+ final ImmutableSet.Builder<ImmutableBitSet> keysBuilder =
ImmutableSet.builder();
if (inputUniqueKeys != null) {
- List<AggregateCall> aggCallList = rel.getAggCallList();
- for (int aggIndex = 0; aggIndex < aggCallList.size(); aggIndex++) {
- AggregateCall call = aggCallList.get(aggIndex);
- if
(PASSTHROUGH_AGGREGATIONS.contains(call.getAggregation().getKind())) {
- Integer inputIndex = call.getArgList().get(0);
- if (inputUniqueKeys.contains(ImmutableBitSet.of(inputIndex))) {
- keysBuilder.add(ImmutableBitSet.of(aggIndex +
rel.getGroupCount()));
- }
- }
Review Comment:
This was half-baked - it wasn't accounting for multiple mappings from input
to output or multi-column keys.
--
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]