[英]Scala code to replace null values of a column in a dataframe which is in form of list
我正在尝试从列表形式的数据集中替换 null 值。 我使用了下面的代码仍然没有给我想要的结果。 我应该怎么办?
我正在使用以下代码:
val mergedDS =customerDS.join(acctstep1,Seq("customerId"),"outer")
.withColumn("numberAccounts", 'numberAccounts.cast("Int"))
.withColumn("totalBalance",'totalBalance.cast("Long"))
// Lets remove all the accounts with missing values for customers
val customerAccountOutputDS = mergedDS.as[CustomerAccountOutput].na.fill(0).show(false)
print(customerAccountOutputDS)
import org.apache.spark.sql.functions._
import org.apache.spark.sql.SparkSession;
object DefaultEmptyArray {
def main(args: Array[String]): Unit = {
val input = List(Bean(List("A","B")),Bean(null),Bean(List("C","D")))
val spark = SparkSession.builder().master("local[*]").getOrCreate();
val df = spark.createDataFrame(input)
df.select("inputList")
.withColumn("outputList",when(col("inputList").isNull,Array[String]()).otherwise(col("inputList")))
.show()
}
}
case class Bean( inputList : List[String])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.