LuciferYang commented on code in PR #56315:
URL: https://github.com/apache/spark/pull/56315#discussion_r3360017978


##########
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:
   Done in 8c24f32 — `RegExpUtils.replace` now takes `source` and `regexp` as 
`String`, so the `nullSafeEval` call site no longer needs the 
`.asInstanceOf[UTF8String]` casts. I also dropped the now-redundant `rep` 
parameter and reuse `replacement` for the error message, since they're the same 
value (`lastReplacement` is built from the rep argument). Thanks for the review!



-- 
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]

Reply via email to