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


##########
common/unsafe/src/main/java/org/apache/spark/sql/catalyst/util/CollationAwareUTF8String.java:
##########
@@ -1267,6 +1268,128 @@ public static UTF8String[] icuSplitSQL(final UTF8String 
string, final UTF8String
     return strings.toArray(new UTF8String[0]);
   }
 
+  /**
+   * Title casing a string according to a new behaviour. Iterates over the 
string and title cases
+   * the first character in each word, and lowercases every other character. 
Handles lowercasing
+   * capital Greek letter sigma ('Σ') separately, taking into account if it 
should be a small final
+   * Greek sigma ('ς') or small non-final Greek sigma ('σ'). Words are 
separated by ASCII
+   * space(\u0020).
+   *
+   * @param target UTF8String to be title cased
+   * @return title cased target
+   */
+  public static UTF8String toTitleCaseICU(UTF8String target) {
+
+    Iterator<Integer> codepointIterator = target.codePointIterator(
+            CodePointIteratorType.CODE_POINT_ITERATOR_MAKE_VALID);
+
+    // Building the title cased target with 'sb'.
+    StringBuilder sb = new StringBuilder();
+    // 'newWord' is true if the current character is the beginning of a word, 
false otherwise.
+    boolean newWord = true;
+    // We are maintaining if the current character is preceded by a cased 
letter.
+    // This is used when lowercasing capital Greek letter sigma ('Σ'), to 
figure out if it should be
+    // lowercased into σ or ς.
+    boolean precededByCasedLetter = false;
+
+    // 'offset' is a byte offset in target's byte array pointing to the 
beginning of the character
+    // that we need to process next(this is only actually used in 
appendLowerCasedGreekCapitalSigma)
+    int offset = 0;

Review Comment:
   just a side note, sharing my thoughts here - perhaps there's no immediate 
action needed at this time
   
   but since we're counting offsets, then why do we need to use the code point 
iterator?
   iiuc, UTF8String code point iterator is already keeping track of the offset
   also, we're eventually reading every code point twice (once using the 
iterator, and once in followedByCasedLetter)
   
   I see two possible ways to go about this:
   - avoid keeping track of the offset separately, and passing it around in the 
new implementation, and instead have a codePoint buffer which allows us to 
"look ahead" one code point to determine what character is next
   - modify (or extend) the existing code point iterator to allow us to do 
whatever it is that we want, in an efficient and readable manner
   
   
   thoughts?



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