You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2020/02/25 23:13:25 UTC

[GitHub] [druid] ccaominh commented on a change in pull request #9384: Add join prefix duplicate/shadowing check

ccaominh commented on a change in pull request #9384: Add join prefix duplicate/shadowing check
URL: https://github.com/apache/druid/pull/9384#discussion_r384184065
 
 

 ##########
 File path: processing/src/main/java/org/apache/druid/segment/join/Joinables.java
 ##########
 @@ -114,4 +122,45 @@ public static boolean isPrefixedBy(final String columnName, final String prefix)
       );
     }).collect(Collectors.toList());
   }
+
+  private static void checkPreJoinableClausesForDuplicatesAndShadowing(
+      final List<PreJoinableClause> preJoinableClauses
+  )
+  {
+    List<String> prefixes = new ArrayList<>();
+    for (PreJoinableClause clause : preJoinableClauses) {
+      prefixes.add(clause.getPrefix());
+    }
+
+    checkPrefixesForDuplicatesAndShadowing(prefixes);
+  }
+
+  /**
+   * Check if any prefixes in the provided list duplicate or shadow each other.
+   *
+   * @param prefixes A mutable list containing the prefixes to check. This list will be sorted by descending
+   *                 string length.
+   */
+  public static void checkPrefixesForDuplicatesAndShadowing(
+      final List<String> prefixes
+  )
+  {
+    // this is a naive approach that assumes we'll typically handle only a small number of prefixes
+    prefixes.sort(DESCENDING_LENGTH_STRING_COMPARATOR);
+    for (int i = 0; i < prefixes.size(); i++) {
+      String prefix = prefixes.get(i);
+      for (int k = i; k < prefixes.size(); k++) {
+        if (i != k) {
 
 Review comment:
   Can the check for `i != k` be removed if `k` is initialized to `i + 1`?

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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org