MaxGekk commented on code in PR #37004:
URL: https://github.com/apache/spark/pull/37004#discussion_r908268235
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala:
##########
@@ -980,3 +980,38 @@ case class RegExpExtractAll(subject: Expression, regexp:
Expression, idx: Expres
newFirst: Expression, newSecond: Expression, newThird: Expression):
RegExpExtractAll =
copy(subject = newFirst, regexp = newSecond, idx = newThird)
}
+
+// scalastyle:off line.size.limit
+@ExpressionDescription(
+ usage = """
+ _FUNC_(str, regexp) - Returns a count of the number of times that the
regular expression pattern `regexp` is matched in the string `str`.
+ """,
+ arguments = """
+ Arguments:
+ * str - a string expression.
+ * regexp - a string representing a regular expression. The regex string
should be a
+ Java regular expression.
+ """,
+ examples = """
+ Examples:
+ > SELECT _FUNC_('Steven Jones and Stephen Smith are the best players',
'Ste(v|ph)en');
+ 2
+ > SELECT _FUNC_('abcdefghijklmnopqrstuvwxyz', '[a-z]{3}');
+ 8
+ """,
+ since = "3.4.0",
+ group = "string_funcs")
+// scalastyle:on line.size.limit
+case class RegExpCount(left: Expression, right: Expression, replacement:
Expression)
+ extends RuntimeReplaceable with InheritAnalysisRules {
Review Comment:
I have removed `InheritAnalysisRules` and have to re-implement the expr to:
```scala
case class RegExpCount(left: Expression, right: Expression) extends
RuntimeReplaceable {
override lazy val replacement: Expression =
Size(RegExpExtractAll(left, right, Literal(0)), legacySizeOfNull = false)
override def prettyName: String = "regexp_count"
override def children: Seq[Expression] = Seq(left, right)
override protected def withNewChildrenInternal(
newChildren: IndexedSeq[Expression]): RegExpCount =
copy(left = newChildren(0), right = newChildren(1))
}
```
and got the test failure on NULL handling:
```diff
-- !query
SELECT regexp_count(null, 'abc')
-- !query schema
-struct<regexp_count(NULL, abc):int>
+struct<>
-- !query output
-NULL
+java.lang.IllegalStateException
+Illegal RuntimeReplaceable: regexp_count(null, abc)
+Replacement is unresolved: size(regexp_extract_all(null, abc, 0), false)
```
--
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]