amaliujia commented on a change in pull request #2006:
URL: https://github.com/apache/calcite/pull/2006#discussion_r473316727
##########
File path: core/src/main/java/org/apache/calcite/rel/RelCollations.java
##########
@@ -199,25 +199,45 @@ public static boolean contains(List<RelCollation>
collations,
* @param keys List of keys
* @return Whether the collection contains the given keys
*/
- private static boolean containsOrderless(RelCollation collation,
+ public static boolean containsOrderless(RelCollation collation,
List<Integer> keys) {
final List<Integer> distinctKeys = Util.distinctList(keys);
final ImmutableBitSet keysBitSet = ImmutableBitSet.of(distinctKeys);
List<Integer> colKeys = Util.distinctList(collation.getKeys());
+
if (colKeys.size() < distinctKeys.size()) {
return false;
+ } else {
+ ImmutableBitSet bitset = ImmutableBitSet.of(
+ colKeys.subList(0, distinctKeys.size()));
+ return bitset.equals(keysBitSet);
+ }
+ }
+
+ /** Returns whether a collation is contained by a given list of keys
regardless ordering.
+ *
+ * @param collation Collation
+ * @param keys List of keys
+ * @return Whether the collection contains the given keys
+ */
+ public static boolean containsOrderless(
+ List<Integer> keys, RelCollation collation) {
+ final List<Integer> distinctKeys = Util.distinctList(keys);
+ List<Integer> colKeys = Util.distinctList(collation.getKeys());
+
+ if (colKeys.size() > distinctKeys.size()) {
+ return false;
+ } else {
+ return colKeys.stream().allMatch(i -> distinctKeys.contains(i));
}
- ImmutableBitSet bitset = ImmutableBitSet.of(
- colKeys.subList(0, distinctKeys.size()));
- return bitset.equals(keysBitSet);
}
/**
* Returns whether one of a list of collations contains the given list of
keys
* regardless the order.
*/
- public static boolean containsOrderless(List<RelCollation> collations,
- List<Integer> keys) {
+ public static boolean collationsContainKeysOrderless(
Review comment:
The reasons that I didn't use overloaded approach
1. these names are in the format of `A verb B`, means the first parameter
contains the second parameter. And arguments of these functions have an
ordering of A and B. I think this is more readable.
2. For Java, List<T> is the same type. For example, List<Integer> and
List<Collation> are both List<T> thus List<Object>. So we cannot overload, for
example `collationsContainKeysOrderless` and `keysContainCollationsOrderless`
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]