peter-toth commented on code in PR #46143:
URL: https://github.com/apache/spark/pull/46143#discussion_r2686858040
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala:
##########
@@ -83,6 +83,27 @@ abstract class StringRegexExpression extends BinaryExpression
matches(regex, input1.asInstanceOf[UTF8String].toString)
}
}
+
+ override def expensive: Boolean = hasExpensiveChild || _expensiveRegex
+
+ private lazy val _expensiveRegex = {
+ // A quick heuristic for expensive a pattern is.
+ left match {
+ case StringLiteral(str) =>
+ // If we have a clear start limited back tracking required.
+ if (str.startsWith("^") || str.startsWith("\\b")) {
+ false
+ } else if (str.contains("+")) {
+ // Greedy matching can be tricky.
Review Comment:
Out of curiosity, why only `+` is considered expensive? Why `*` and `{m,n}`
are not?
--
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]