我有以下代码片段:
package org.test.test.datahelper
import org.apache.spark.rdd.RDD
import org.apache.spark.sql._
class WeatherHelper(sparkSession: SparkSession, weather: DataFrame) {
def prepareRRRColumn: DataFrame = {
import org.apache.spark.sql.functions
weather.withColumn("Year", year(col("DateTime")))
weather
}
}
问题是 Scala(或者可能是 IntelliJ IDEA)并没有year像col(Cannot resolve symbol year并且col恭敬地)那样看到方法,尽管必要的导入只是上面的一行(但是,即使导入是全局的,它也不起作用)。按照我的源代码,org.apache.spark.sql.functions我发现了以下几行:
def col(colName : scala.Predef.String) : org.apache.spark.sql.Column = { /* compiled code */ }
def year(e : org.apache.spark.sql.Column) : org.apache.spark.sql.Column = { /* compiled code */ }
即这两种方法都存在。我究竟做错了什么?