gengliangwang commented on code in PR #56315:
URL: https://github.com/apache/spark/pull/56315#discussion_r3359163954
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala:
##########
@@ -738,26 +736,8 @@ case class RegExpReplace(subject: Expression, regexp:
Expression, rep: Expressio
lastReplacementInUTF8 = r.asInstanceOf[UTF8String].clone()
lastReplacement = lastReplacementInUTF8.toString
}
- val source = s.toString()
- val position = i.asInstanceOf[Int] - 1
- if (position == 0 || position < source.length) {
- val m = pattern.matcher(source)
- m.region(position, source.length)
- result.delete(0, result.length())
- while (m.find) {
- try {
- m.appendReplacement(result, lastReplacement)
- } catch {
- case NonFatal(e) =>
- throw QueryExecutionErrors.invalidRegexpReplaceError(s.toString,
- p.toString, r.toString, i.asInstanceOf[Int], e)
- }
- }
- m.appendTail(result)
- UTF8String.fromString(result.toString)
- } else {
- s
- }
+ RegExpUtils.replace(pattern, s.asInstanceOf[UTF8String], lastReplacement,
Review Comment:
I would prefer using Java String as the method parameter here. So that we
can avoid all these `.asInstanceOf[UTF8String]`
--
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]