我想将数据框架构中的年,月和日列从整数转换为字符串。
|-- year: integer (nullable = true)
|-- month: integer (nullable = true)
|-- day: integer (nullable = true)
它应返回相同的DF,但特定列的列类型更改为String
。
我遇到的错误是
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
}
我的功能出了什么问题?