Last active
February 1, 2018 13:43
-
-
Save johnmuller87/d10560bb6b88b8a4d2dbfffd6d3407ad to your computer and use it in GitHub Desktop.
Example UDF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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