[英]Convert String to type column Spark
Code:代码:
import org.apache.spark.sql.DataFrame
import org.apache.spark.sql.Column
def func(rawDF: DataFrame,primaryKey: Column, orderKey: Column): DataFrame = {
//some process
return newDf
}
I am trying to create a new processed DF from existing raw DF with the function above.我正在尝试使用上述函数从现有的原始 DF 创建一个新的处理过的 DF。
Code:代码:
var processedDF = func(rawDF,"col1","col2")
Error:错误:
<console>:73: error: type mismatch;
found : String("col1")
required: org.apache.spark.sql.Column
var processedDF = func(rawDF,"col1","col2")
^
Any suggestions on how to change the type of the function parameter from String to org.apache.spark.sql.Column关于如何将函数参数的类型从 String 更改为 org.apache.spark.sql.Column 的任何建议
Either任何一个
import org.apache.spark.sql.functions.col
func(rawDF, col("col1"), col("col2"))
or或者
func(rawDF, rawDF("col1"), rawDF("col2"))
or provide Column
directly through $
(where spark
is SparkSession
object)或直接通过
$
提供Column
(其中spark
是SparkSession
对象)
import spark.implicits.StringToColumn
func(rawDF, $"col1", $"col2")
or Symbol
或
Symbol
import spark.implicits.symbolToColumn
func(rawDF, 'col1, 'col2)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.