Skip to content

Commit

Permalink
[SPARK-30759][SQL][TESTS][FOLLOWUP] Check cache initialization in Str…
Browse files Browse the repository at this point in the history
…ingRegexExpression

### What changes were proposed in this pull request?
Added new test to `RegexpExpressionsSuite` which checks that `cache` of compiled pattern is set when the `right` expression (pattern in `LIKE`) is a foldable expression.

### Why are the changes needed?
To be sure that `cache` in `StringRegexExpression` is initialized for foldable patterns.

### Does this PR introduce any user-facing change?
No

### How was this patch tested?
By running the added test in `RegexpExpressionsSuite`.

Closes apache#27547 from MaxGekk/regexp-cache-test.

Authored-by: Maxim Gekk <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
  • Loading branch information
MaxGekk authored and Seongjin Cho committed Apr 14, 2020
1 parent 4c3877e commit 1a690bf
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,4 +329,12 @@ class RegexpExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
checkEvaluation(StringSplit(s1, s2, -1), null, row3)
}

test("SPARK-30759: cache initialization for literal patterns") {
val expr = "A" like Literal.create("a", StringType)
expr.eval()
val cache = expr.getClass.getSuperclass
.getDeclaredFields.filter(_.getName.endsWith("cache")).head
cache.setAccessible(true)
assert(cache.get(expr).asInstanceOf[java.util.regex.Pattern].pattern().contains("a"))
}
}

0 comments on commit 1a690bf

Please sign in to comment.