Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,14 @@ public static int findInSet(final UTF8String match, final UTF8String set, int co
*/
public static int lowercaseIndexOf(final UTF8String target, final UTF8String pattern,
final int start) {
if (pattern.numChars() == 0) return target.indexOfEmpty(start);
if (pattern.numChars() == 0) return target.indexOfEmpty(target, start);
return lowercaseFind(target, pattern.toLowerCase(), start);
}

public static int indexOf(final UTF8String target, final UTF8String pattern,
final int start, final int collationId) {
if (pattern.numBytes() == 0) {
return target.indexOfEmpty(start);
return target.indexOfEmpty(target, start);
}

StringSearch stringSearch = CollationFactory.getStringSearch(target, pattern, collationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -780,8 +780,8 @@ public UTF8String repeat(int times) {
* @param start the start position of the current string for searching
* @return the position of the first occurrence of the empty substr (now, always 0)
*/
public int indexOfEmpty(int start) {
return 0; // TODO: Fix this behaviour (SPARK-48284)
public int indexOfEmpty(UTF8String v, int start) {
return start >= numChars() ? 0 : start;
}

/**
Expand All @@ -794,7 +794,7 @@ public int indexOfEmpty(int start) {
*/
public int indexOf(UTF8String v, int start) {
if (v.numBytes() == 0) {
return indexOfEmpty(start);
return indexOfEmpty(v, start);
}

// locate to the start position.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ public void indexOf() {
assertEquals(0, EMPTY_UTF8.indexOf(EMPTY_UTF8, 0));
assertEquals(-1, EMPTY_UTF8.indexOf(fromString("l"), 0));
assertEquals(0, fromString("hello").indexOf(EMPTY_UTF8, 0));
assertEquals(2, fromString("hello").indexOf(EMPTY_UTF8, 2));
assertEquals(0, fromString("hello").indexOf(EMPTY_UTF8, 9));
assertEquals(2, fromString("hello").indexOf(fromString("l"), 0));
assertEquals(3, fromString("hello").indexOf(fromString("l"), 3));
assertEquals(-1, fromString("hello").indexOf(fromString("a"), 0));
Expand Down