Skip to content

Instantly share code, notes, and snippets.

@marcolivierarsenault
Created April 12, 2019 01:44
Show Gist options
  • Save marcolivierarsenault/fcad2f29903c27ef06fab16a02d12729 to your computer and use it in GitHub Desktop.
Save marcolivierarsenault/fcad2f29903c27ef06fab16a02d12729 to your computer and use it in GitHub Desktop.
def findMatchingPatterns(regexes: ArrayList[String]): UserDefinedFunction = {
udf((value: String) => {
for {
text <- Option(value)
matches = regexes.asScala.filter(r => Pattern.matches(r, text))
if matches.nonEmpty
} yield matches
}, ArrayType(StringType))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment