cloud-fan commented on a change in pull request #29891:
URL: https://github.com/apache/spark/pull/29891#discussion_r504728597
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
##########
@@ -397,21 +437,33 @@ case class RegExpReplace(subject: Expression, regexp:
Expression, rep: Expressio
$termLastReplacementInUTF8 = $rep.clone();
$termLastReplacement = $termLastReplacementInUTF8.toString();
}
- $classNameStringBuffer $termResult = new $classNameStringBuffer();
- java.util.regex.Matcher $matcher =
$termPattern.matcher($subject.toString());
-
- while ($matcher.find()) {
- $matcher.appendReplacement($termResult, $termLastReplacement);
+ String $source = $subject.toString();
+ int $position = $pos - 1;
+ if ($position < $source.length()) {
+ $classNameStringBuffer $termResult = new $classNameStringBuffer();
+ java.util.regex.Matcher $matcher = $termPattern.matcher($source);
+ $matcher.region($position, $source.length());
+
+ while ($matcher.find()) {
+ $matcher.appendReplacement($termResult, $termLastReplacement);
+ }
+ $matcher.appendTail($termResult);
+ ${ev.value} = UTF8String.fromString($termResult.toString());
+ $termResult = null;
+ } else {
+ ${ev.value} = $subject;
}
- $matcher.appendTail($termResult);
- ${ev.value} = UTF8String.fromString($termResult.toString());
- $termResult = null;
$setEvNotNull
"""
})
}
}
+object RegExpReplace {
+ def apply(subject: Expression, regexp: Expression, rep: Expression):
RegExpReplace =
+ new RegExpReplace(subject, regexp, rep, Literal(1))
Review comment:
I'm surprised this works. `FunctionRegistry.expression` searches for
constructors, not `apply` methods. I thought we will fail to call
`regexp_replace` function without the position parameter.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]