You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2020/08/19 08:42:51 UTC

[GitHub] [calcite] rubenada commented on a change in pull request #2006: [CALCITE-4015] Pass through parent collation request on subset or sup…

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



##########
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:
       I would name this method (and the following one) just `containsOrderless`, i.e. provide 4 overloaded methods with that name.




----------------------------------------------------------------
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:
users@infra.apache.org