Last active
July 5, 2019 01:11
-
-
Save dongjinahn/5e0aa1c98a16ddd61f4e49a014fdf1e9 to your computer and use it in GitHub Desktop.
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
import org.apache.spark.sql.functions | |
type myFunctionType = (Int, Long, String) => Int | |
val myFunction: myFunctionType = (i, l, str) => i + l.toInt + Integer.parseInt(str) | |
val myUDF = functions.udf(myFunction) |
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 myFunction2Type = (Long, java.lang.Double, String) => Tuple2[Double, String] | |
val myFunction2: myFunction2Type = (l, d, str) => (d + l, str) | |
val myUDF2 = functions.udf(myFunction2) |
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
val colList = List[Column]( | |
originalDF("long_column"), | |
originalDF("double_column"), | |
originalDF("string_column") | |
) | |
val processedDF = originalDF | |
.withColumn("newCol", myUDF2(colList:_*)) | |
.select("newCol._1", "newCol._2") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment