【发布时间】:2022-12-09 23:10:17
【问题描述】:
我很好奇为什么这在数据帧上的 Spark Scala 中不起作用:
df.withColumn("answer", locate(df("search_string"), col("hit_songs"), pos=1))
它适用于 UDF,但不是按照上面的那样。 Col 与 String 方面。看起来很尴尬,缺乏方面。 IE。如何将列转换为字符串以传递给需要 String 的位置。
df("search_string") 允许生成字符串是我的理解。
但是得到的错误是:
command-679436134936072:15: error: type mismatch;
found : org.apache.spark.sql.Column
required: String
df.withColumn("answer", locate(df("search_string"), col("hit_songs"), pos=1))
【问题讨论】:
-
你得到什么错误?
-
@GaurangShah 更新了问题
-
我也收到 pyspark 错误
TypeError: 'DataFrame' object is not callable。火花3 -
这是其他地方的问题。但这是关于scala的
-
对不起。无法理解你的问题。我以为你说它在 python 中工作。下面的 API 总是相同的。所以它不可能在 python 中工作,但在 scala 中不行。我刚刚测试了它。它在 Python 中不起作用。原因是,API 需要字符串而不是列。两者都是不同的数据类型。
标签: scala apache-spark