Last active
April 5, 2017 22:36
-
-
Save gbraccialli/cb9de4ff862adaddfc65a83497ad09fe to your computer and use it in GitHub Desktop.
This file contains hidden or 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
case class Person (name: String, age: Int) | |
val df = sc.parallelize(List(Person("Guilherme", 35), Person("Isabela", 6), Person("Daniel", 3))).toDF | |
def wordsLengthScala(a: Any): Array[Int] = { | |
a match { | |
case s: String => {s.split(" ").map(s => s.length)} | |
case i: Integer => {Array(i)} | |
} | |
} | |
val wordsLengthScalaUDF = udf(wordsLengthScala _) | |
df.printSchema | |
df.show | |
df.select(wordsLengthScalaUDF(col("name")),wordsLengthScalaUDF(col("age"))).show | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment