zhangxinyao88 commented on code in PR #59346:
URL: https://github.com/apache/spark/pull/59346#discussion_r4244637253


##########
common/unsafe/src/main/java/org/apache/spark/sql/catalyst/util/CollationAwareUTF8String.java:
##########
@@ -928,8 +928,9 @@ public static int indexOf(final UTF8String target, final 
UTF8String pattern,
   public static int indexOf(final UTF8String target, final UTF8String pattern,
       final int start, final int occurrence, final int collationId) {
     assert occurrence > 0;
+    if (start == 0) return MATCH_NOT_FOUND;
     if (pattern.numBytes() == 0) return target.indexOfEmpty(start);
-    if (target.numBytes() == 0 || start == 0) return MATCH_NOT_FOUND;
+    if (target.numBytes() == 0) return MATCH_NOT_FOUND;

Review Comment:
   > Is this the cleanest solution?
   
   The existing `instr` documentation explicitly says `start = 0 returns 0`:
   
https://github.com/apache/spark/blob/215a1460d9d4acdac6f72b42c28ab60b9ff5b7fe/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala#L1835
   
   The helper returns `-1`, which SQL converts to `0` by adding 1:
   
https://github.com/apache/spark/blob/215a1460d9d4acdac6f72b42c28ab60b9ff5b7fe/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala#L1958
   
   Checking zero start before the empty-pattern shortcut is the smallest fix. 
The helper docs now state this briefly in `@param start`.
   



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