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:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to