rubenada commented on a change in pull request #2006:
URL: https://github.com/apache/calcite/pull/2006#discussion_r473930318



##########
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:
       Ok, I understand, thanks for the explanation.




----------------------------------------------------------------
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]


Reply via email to