Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/19797#discussion_r153973665
--- Diff:
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/RegexpExpressionsSuite.scala
---
@@ -178,6 +179,16 @@ class RegexpExpressionsSuite extends SparkFunSuite
with ExpressionEvalHelper {
checkEvaluation(nonNullExpr, "num-num", row1)
}
+ test("SPARK-22570: should not create a lot of instance variables") {
+ val N = 16000
+ val expr = RegExpReplace(Literal("100"), Literal("(\\d+)"),
Literal("num"))
+ val ctx = new CodegenContext
+ (1 to N).map(_ => expr.genCode(ctx).code)
+ // four global variables (lastRegex, pattern, lastReplacement, and
lastReplacementInUTF8)
+ // are always required
+ assert(ctx.mutableStates.length == 4 * N)
--- End diff --
I think we can simplify it to
```
val ctx = new CodegenContext
RegExpReplace(Literal("100"), Literal("(\\d+)"),
Literal("num")).genCode(ctx)
// ...
assert(ctx.mutableStates.length == 4)
```
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]