zabetak commented on code in PR #4013:
URL: https://github.com/apache/calcite/pull/4013#discussion_r1820905037
##########
core/src/main/java/org/apache/calcite/rel/metadata/RelMdUniqueKeys.java:
##########
@@ -184,19 +180,12 @@ private static Set<ImmutableBitSet>
getProjectUniqueKeys(SingleRel rel, RelMetad
continue;
}
// colMask is mapped to output project, however, the column can be
mapped more than once:
- // select id, id, id, unique2, unique2
- // the resulting unique keys would be {{0},{3}}, {{0},{4}},
{{0},{1},{4}}, ...
-
- Iterable<List<ImmutableBitSet>> product =
- Linq4j.product(
- Util.transform(colMask, in ->
- Util.filter(
- requireNonNull(mapInToOutPos.get(in),
- () -> "no entry for column " + in
- + " in mapInToOutPos: " +
mapInToOutPos).powerSet(),
- bs -> !bs.isEmpty())));
-
- resultBuilder.addAll(Util.transform(product, ImmutableBitSet::union));
+ // select key1, key1, val1, val2, key2 from ...
+ // the resulting unique keys would be {{0},{4}}, {{1},{4}}
Review Comment:
I am afraid that the above suggestion is incorrect. The `UniqueKeys`
metadata does not return record/row values but column ordinals.
To understand these comments it is important to have read the Javadoc of the
`UniqueKeys` interface before.
`{0}` refers to the column at position zero i.e., the first occurrence of
column key1 in the query.
`{1}`refers to the column at position one i.e., the second occurrence of
column key1 in the query.
...
`{4}`refers to the column at position four i.e., column key2 in the query.
If this is not clear from the Javadoc of the `UniqueKeys` interface then we
should improve that part of the documentation and not this internal low-level
comments. The part here assumes that the developer understands what the result
of this method is.
--
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]