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
Type | Time(s) | |
---|---|---|
Python UDF | 43.0632779598 | |
Python Vectorized UDF | 13.9144539833 | |
Scala UDF | 0.257154205 |
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
# create the jar using SBT | |
sbt clean assembly | |
# Pass the jar to the PySpark session | |
pyspark --jars [path/to/jar/x.jar] |
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
# Pre Spark 2.1, use the tag 'pre-2.1' | |
spark._jvm.com.ing.wbaa.spark.udf.ValidateIBAN.registerUDF(spark._jsparkSession) | |
# Spark 2.1+, use the tag '2.1+' | |
from pyspark.sql.types import BooleanType | |
sqlContext.registerJavaFunction("validate_iban", "com.ing.wbaa.spark.udf.ValidateIBAN", BooleanType()) | |
# Spark 2.3+ use the tag '2.1+' | |
from pyspark.sql.types import BooleanType | |
spark.udf.registerJavaFunction("validate_iban", "com.ing.wbaa.spark.udf.ValidateIBAN", BooleanType()) | |
# Use your 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] { |