kiszk commented on a change in pull request #21985: [SPARK-24884][SQL] add 
regexp_extract_all support
URL: https://github.com/apache/spark/pull/21985#discussion_r317401887
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala
 ##########
 @@ -386,6 +388,41 @@ case class RegExpReplace(subject: Expression, regexp: 
Expression, rep: Expressio
   }
 }
 
+abstract class RegExpExtractBase extends TernaryExpression with 
ImplicitCastInputTypes {
+  // last regex in string, we will update the pattern iff regexp value changed.
+  @transient protected var lastRegex: UTF8String = _
+  // last regex pattern, we cache it for performance concern
+  @transient protected var pattern: Pattern = _
+  override def inputTypes: Seq[AbstractDataType] = Seq(StringType, StringType, 
IntegerType)
+
+  protected def getMatcher(s: Any, p: Any) = {
+    if (!p.equals(lastRegex)) {
+      // regex value changed
+      lastRegex = p.asInstanceOf[UTF8String].clone()
+      pattern = Pattern.compile(lastRegex.toString)
+    }
+    pattern.matcher(s.toString)
+  }
+
+  protected def getDoGenCodeVals(ctx: CodegenContext, ev: ExprCode) = {
+    val classNamePattern = classOf[Pattern].getCanonicalName
+    val matcher = ctx.freshName("matcher")
+    val matchResult = ctx.freshName("matchResult")
+
+    val termLastRegex = ctx.addMutableState("UTF8String", "lastRegex")
+    val termPattern = ctx.addMutableState(classNamePattern, "pattern")
+
+    val setEvNotNull = if (nullable) {
+      s"${ev.isNull} = false;"
+    } else {
+      ""
+    }
+
+    (classNamePattern, matcher, matchResult, termLastRegex, termPattern, 
setEvNotNull)
+
 
 Review comment:
   nit: delete empty line

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


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to