Re: [PR] [SPARK-47295] Added ICU StringSearch for 'startsWith' and 'endsWith' functions [spark]

2024-03-08 Thread via GitHub


stevomitric commented on code in PR #45421:
URL: https://github.com/apache/spark/pull/45421#discussion_r1517360690


##
common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java:
##
@@ -410,7 +412,9 @@ public boolean endsWith(final UTF8String suffix, int 
collationId) {
 if (collationId == CollationFactory.LOWERCASE_COLLATION_ID) {
   return this.toLowerCase().endsWith(suffix.toLowerCase());
 }
-return matchAt(suffix, numBytes - suffix.numBytes, collationId);
+if (suffix.numBytes == 0 || this.numBytes == 0) return suffix.numBytes==0;
+
+return CollationFactory.getStringSearch(this, suffix, 
collationId).last()==this.numChars()-suffix.numChars();

Review Comment:
   Separated both `collatedEndsWith` and `collatedStartsWith`



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



Re: [PR] [SPARK-47295] Added ICU StringSearch for 'startsWith' and 'endsWith' functions [spark]

2024-03-08 Thread via GitHub


stevomitric commented on code in PR #45421:
URL: https://github.com/apache/spark/pull/45421#discussion_r1517360283


##
common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java:
##
@@ -396,7 +396,9 @@ public boolean startsWith(final UTF8String prefix, int 
collationId) {
 if (collationId == CollationFactory.LOWERCASE_COLLATION_ID) {
   return this.toLowerCase().startsWith(prefix.toLowerCase());
 }
-return matchAt(prefix, 0, collationId);

Review Comment:
   Deleted



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



Re: [PR] [SPARK-47295] Added ICU StringSearch for 'startsWith' and 'endsWith' functions [spark]

2024-03-07 Thread via GitHub


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


##
common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java:
##
@@ -410,7 +412,9 @@ public boolean endsWith(final UTF8String suffix, int 
collationId) {
 if (collationId == CollationFactory.LOWERCASE_COLLATION_ID) {
   return this.toLowerCase().endsWith(suffix.toLowerCase());
 }
-return matchAt(suffix, numBytes - suffix.numBytes, collationId);
+if (suffix.numBytes == 0 || this.numBytes == 0) return suffix.numBytes==0;
+
+return CollationFactory.getStringSearch(this, suffix, 
collationId).last()==this.numChars()-suffix.numChars();

Review Comment:
   for clarity, I think we can separate this out into `private boolean 
collatedEndsWith`



##
common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java:
##
@@ -410,7 +412,9 @@ public boolean endsWith(final UTF8String suffix, int 
collationId) {
 if (collationId == CollationFactory.LOWERCASE_COLLATION_ID) {
   return this.toLowerCase().endsWith(suffix.toLowerCase());
 }
-return matchAt(suffix, numBytes - suffix.numBytes, collationId);
+if (suffix.numBytes == 0 || this.numBytes == 0) return suffix.numBytes==0;
+
+return CollationFactory.getStringSearch(this, suffix, 
collationId).last()==this.numChars()-suffix.numChars();

Review Comment:
   for clarity, I think we can separate this out into `private boolean 
collatedEndsWith(...)`



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



Re: [PR] [SPARK-47295] Added ICU StringSearch for 'startsWith' and 'endsWith' functions [spark]

2024-03-07 Thread via GitHub


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


##
common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java:
##
@@ -396,7 +396,9 @@ public boolean startsWith(final UTF8String prefix, int 
collationId) {
 if (collationId == CollationFactory.LOWERCASE_COLLATION_ID) {
   return this.toLowerCase().startsWith(prefix.toLowerCase());
 }
-return matchAt(prefix, 0, collationId);

Review Comment:
   if there's code in `UTF8String` that's no longer used, we should delete it 
(for example, the overloaded `matchAt`)



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



Re: [PR] [SPARK-47295] Added ICU StringSearch for 'startsWith' and 'endsWith' functions [spark]

2024-03-07 Thread via GitHub


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


##
common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java:
##
@@ -384,27 +387,47 @@ public boolean startsWith(final UTF8String prefix) {
   }
 
   public boolean startsWith(final UTF8String prefix, int collationId) {
-if (CollationFactory.fetchCollation(collationId).isBinaryCollation) {
+if (collationId == CollationFactory.DEFAULT_COLLATION_ID) {
   return this.startsWith(prefix);
 }
 if (collationId == CollationFactory.LOWERCASE_COLLATION_ID) {
   return this.toLowerCase().startsWith(prefix.toLowerCase());
 }
-return matchAt(prefix, 0, collationId);
+if (prefix.numBytes == 0 || this.numBytes == 0) return prefix.numBytes==0;
+
+String prefixString = 
StandardCharsets.UTF_8.decode(prefix.getByteBuffer()).toString(),
+patternString = 
StandardCharsets.UTF_8.decode(this.getByteBuffer()).toString();
+
+StringSearch search = new StringSearch(prefixString,

Review Comment:
   referring to this PR: https://github.com/apache/spark/pull/45382
   you can see that we shouldn't instantiate StringSearch objects outside of 
CollationFactory as well



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



Re: [PR] [SPARK-47295] Added ICU StringSearch for 'startsWith' and 'endsWith' functions [spark]

2024-03-07 Thread via GitHub


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


##
common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java:
##
@@ -31,6 +32,8 @@
 import com.esotericsoftware.kryo.io.Input;
 import com.esotericsoftware.kryo.io.Output;
 
+import com.ibm.icu.text.RuleBasedCollator;
+import com.ibm.icu.text.StringSearch;

Review Comment:
   (see comment below)



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



Re: [PR] [SPARK-47295] Added ICU StringSearch for 'startsWith' and 'endsWith' functions [spark]

2024-03-07 Thread via GitHub


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


##
common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java:
##
@@ -384,27 +387,47 @@ public boolean startsWith(final UTF8String prefix) {
   }
 
   public boolean startsWith(final UTF8String prefix, int collationId) {
-if (CollationFactory.fetchCollation(collationId).isBinaryCollation) {
+if (collationId == CollationFactory.DEFAULT_COLLATION_ID) {
   return this.startsWith(prefix);
 }
 if (collationId == CollationFactory.LOWERCASE_COLLATION_ID) {
   return this.toLowerCase().startsWith(prefix.toLowerCase());
 }
-return matchAt(prefix, 0, collationId);
+if (prefix.numBytes == 0 || this.numBytes == 0) return prefix.numBytes==0;
+
+String prefixString = 
StandardCharsets.UTF_8.decode(prefix.getByteBuffer()).toString(),
+patternString = 
StandardCharsets.UTF_8.decode(this.getByteBuffer()).toString();
+
+StringSearch search = new StringSearch(prefixString,
+new StringCharacterIterator(patternString),
+(RuleBasedCollator) 
CollationFactory.fetchCollation(collationId).collator
+);
+
+return search.first()==0;
   }
 
   public boolean endsWith(final UTF8String suffix) {
 return matchAt(suffix, numBytes - suffix.numBytes);
   }
 
   public boolean endsWith(final UTF8String suffix, int collationId) {
-if (CollationFactory.fetchCollation(collationId).isBinaryCollation) {
+if (collationId == CollationFactory.DEFAULT_COLLATION_ID) {

Review Comment:
   (see comment above)



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



Re: [PR] [SPARK-47295] Added ICU StringSearch for 'startsWith' and 'endsWith' functions [spark]

2024-03-07 Thread via GitHub


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


##
common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java:
##
@@ -384,27 +387,47 @@ public boolean startsWith(final UTF8String prefix) {
   }
 
   public boolean startsWith(final UTF8String prefix, int collationId) {
-if (CollationFactory.fetchCollation(collationId).isBinaryCollation) {
+if (collationId == CollationFactory.DEFAULT_COLLATION_ID) {

Review Comment:
   we shouldn't make changes to the original logic, this part was fine
   in this PR, we should only focus on the "third" type of collations 
(non-binary, non-lowercase)



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



Re: [PR] [SPARK-47295] Added ICU StringSearch for 'startsWith' and 'endsWith' functions [spark]

2024-03-07 Thread via GitHub


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


##
common/unsafe/src/main/java/org/apache/spark/unsafe/types/UTF8String.java:
##
@@ -31,6 +32,8 @@
 import com.esotericsoftware.kryo.io.Input;
 import com.esotericsoftware.kryo.io.Output;
 
+import com.ibm.icu.text.RuleBasedCollator;

Review Comment:
   we should not expose collator outside of `CollationFactory`



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org