uros-db commented on code in PR #47040:
URL: https://github.com/apache/spark/pull/47040#discussion_r1650979473


##########
common/unsafe/src/main/java/org/apache/spark/sql/catalyst/util/CollationFactory.java:
##########
@@ -828,4 +843,52 @@ public static byte[] getCollationKeyBytes(UTF8String 
input, int collationId) {
     }
   }
 
+  /**
+   * Returns same string if collation name is valid or the closest suggestion 
if it is invalid.
+   */
+  public static String getClosestSuggestionOnInvalidName(String collationName) 
{
+    String[] validRootNames;
+    String[] validModifiers;
+    if (collationName.startsWith("UTF8_")) {
+      validRootNames = new String[]{
+        Collation.CollationSpecUTF8Binary.UTF8_BINARY_COLLATION.collationName,
+        Collation.CollationSpecUTF8Binary.UTF8_LCASE_COLLATION.collationName
+      };
+      validModifiers = new String[0];
+    } else {
+      validRootNames = getICULocaleNames();
+      validModifiers = new String[]{"_CI", "_AI", "_CS", "_AS"};
+    }
+
+    // Split modifiers and locale name.
+    final int MODIFIER_LENGTH = 3;

Review Comment:
   I wonder if we have this somewhere (else) in CollationFactory already? If 
not, perhaps that (outside of `getClosestSuggestionOnInvalidName`) would be the 
place to put it



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to