Skip to content

Instantly share code, notes, and snippets.

@johnmuller87
Last active February 1, 2018 13:43
Show Gist options
  • Save johnmuller87/d10560bb6b88b8a4d2dbfffd6d3407ad to your computer and use it in GitHub Desktop.
Save johnmuller87/d10560bb6b88b8a4d2dbfffd6d3407ad to your computer and use it in GitHub Desktop.
Example UDF
package com.ing.wbaa.spark.udf
import org.apache.spark.sql.api.java.UDF1
import org.iban4j._
import scala.util.Try
/** Validate IBAN (Whitespace removed). If valid, no execption is thrown in IbanUtil and true is returned
* If Invalid, an exception is thrown and false is returned. If null, false is also returned.
*/
class ValidateIBAN extends UDF1[String, Boolean] {
override def call(potentialIBAN: String): Boolean = {
Option(potentialIBAN).exists(ibanString => Try(
IbanUtil.validate(
ibanString.replaceAll("\\s", "")
)
).isSuccess)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment