-
-
Save franchb/ade144a1ba9d09cc348aa1a59fbc8e54 to your computer and use it in GitHub Desktop.
How to apply a function to every row in a Spark DataFrame.
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
def findNull(row:Row):String = { | |
if (row.anyNull) { | |
val indices = (0 to row.length-1).toArray.filter(i => row.isNullAt(i)) | |
indices.mkString(",") | |
} | |
else "-1" | |
} | |
sqlContext.udf.register("findNull", findNull _) | |
df = df.withColumn("MissingGroups",callUDF("findNull",struct(df.columns.map(df(_)) : _*))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment