如何将 Spark 的 col() 应用于包含列名的 Array[String]?
How to apply Spark's col() to Array[String] containing the columns name?
如果我有一个 Array[String]
包含我需要在 select()
函数中使用的列,我如何以最设计的方式应用它们?
.select(from_json(col("value").cast("string"), schema).as("data"), col("oneColumn"))
我想用数组中的名称放置几列来代替 col("oneColumn")
来自 的答案帮不了我,因为它们处理的是字符串列表,而我已经有一个 Column
对象,无法将列集合用作 select()
正在准备列列表
val cols: List[Column] = headers.toList.map(name => col(name))
val cols1 = cols :+ from_json(col("value").cast("string"), schema).as("data")
然后
.select(cols1: _*)
如果我有一个 Array[String]
包含我需要在 select()
函数中使用的列,我如何以最设计的方式应用它们?
.select(from_json(col("value").cast("string"), schema).as("data"), col("oneColumn"))
我想用数组中的名称放置几列来代替 col("oneColumn")
来自 Column
对象,无法将列集合用作 select()
正在准备列列表
val cols: List[Column] = headers.toList.map(name => col(name))
val cols1 = cols :+ from_json(col("value").cast("string"), schema).as("data")
然后
.select(cols1: _*)