You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "uros-b (via GitHub)" <gi...@apache.org> on 2026/08/30 23:38:43 UTC
Re: [PR] [SPARK-59063][SQL] Use a byte-length guard in LikeSimplification for 'prefix%suffix' [spark]
uros-b commented on code in PR #58362:
URL: https://github.com/apache/spark/pull/58362#discussion_r3890866686
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/expressions.scala:
##########
@@ -830,11 +830,13 @@ object LikeSimplification extends Rule[LogicalPlan] with PredicateHelper {
case endsWith(postfix) =>
Some(EndsWith(input, Literal.create(postfix, input.dataType)))
// 'a%a' pattern is basically same with 'a%' && '%a'.
- // However, the additional `Length` condition is required to prevent 'a' match 'a%a'.
+ // However, the additional length condition is required to prevent 'a' match 'a%a'.
+ // Since StartsWith/EndsWith already pin the prefix and suffix at code-point boundaries,
+ // a byte-length guard (OctetLength, O(1)) is equivalent to a char-length guard and cheaper.
case startsAndEndsWith(prefix, postfix) =>
- Some(And(GreaterThanOrEqual(Length(input),
- Literal.create(prefix.codePointCount(0, prefix.length)
- + postfix.codePointCount(0, postfix.length))),
+ Some(And(GreaterThanOrEqual(OctetLength(input),
Review Comment:
The main thing to be aware of here is that collation-aware anchors can match code points with different UTF-8 lengths.
--
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-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org