首页 > 其他分享 >dataFrame把某列类型为array<double>或者array<string>数组里的值为null的置换为非null

dataFrame把某列类型为array<double>或者array<string>数组里的值为null的置换为非null

时间:2022-12-14 17:15:03浏览次数:45  
标签:case 某列 NOVALUE List item array null

----把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]) = {
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
})
}

}

标签:case,某列,NOVALUE,List,item,array,null
From: https://www.cnblogs.com/ivyJ/p/16982662.html

相关文章