Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,20 @@ trait StringRegexExpression extends Expression
Pattern.compile(escape(str))
}

var lastPatternStr: String = null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can keep lastPattern as Pattern, and compare it to the current pattern via lastPattern.pattern() == patternStr. No need to keep lastPattern as a string.

Copy link
Contributor Author

@beliefer beliefer Feb 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your review.
Of course,I can do like this. I just followed the way of RegExpExtract and RegExpReplace here.

var compiledPattern: Pattern = null

def nullSafeMatch(input1: Any, input2: Any): Any = {
val s = input2.asInstanceOf[UTF8String].toString
val regex = if (cache == null) compile(s) else cache
val patternStr = input2.asInstanceOf[UTF8String].toString
val regex = if (cache == null) {
if (!(patternStr).equals(lastPatternStr)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any reasons to not use patternStr != lastPatternStr?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, I see this is a copy-paste from Java codegen

compiledPattern = compile(patternStr)
lastPatternStr = patternStr
}
compiledPattern
} else {
cache
}
if(regex == null) {
null
} else {
Expand Down