----把array<double>里的null值转换为0:
df.withColumn("Value", replaceArrayNullToZeroUDF(col("Value")))
def replaceArrayNullToNOVALUEUDF = udf(replaceArrayNullToNOVALUE)
def replaceArrayNullToZero: (List[String] => List[String]) = {
s =>
s match {
case null => List()
case ::(head, next) =>
s.map(item => {
val value = item match {
case null => "0"
case "" => "0"
case "null" => "0"
case _ => item
}
value
})
}
}
----把array<string>里的null值转换为字符串NOVALUE:
def replaceArrayNullToNOVALUE: (List[String] => List[String]) = {标签:case,某列,NOVALUE,List,item,array,null From: https://www.cnblogs.com/ivyJ/p/16982662.html
s =>
s match {
case null => List()
case _ => s.map(item => {
val value = item match {
case null => "NOVALUE"
case "" => "NOVALUE"
case "null" => "NOVALUE"
case _ => item
}
value
})
}
}