Scala递归覆盖DF

时间:2019-07-29 03:08:47

标签: scala apache-spark

我想将数据框架构中的年,月和日列从整数转换为字符串。

 |-- year: integer (nullable = true)
 |-- month: integer (nullable = true)
 |-- day: integer (nullable = true)

它应返回相同的DF,但特定列的列类型更改为String

我遇到的错误是

enter image description here 这是我的功能:

def transformDate(df: Dataset[Row], spark: SparkSession): Dataset[Row] = {
    val cols = Seq("month","day","year")

    for (col <- cols) {
    val df  = df.withColumn(col, $"col".cast(org.apache.spark.sql.types.StringType))
}
    df
    }

我的功能出了什么问题?

0 个答案:

没有答案
相关问题