对象DataFrame不是包org.apache.spark.sql的成员

Zim*_*ang 6 apache-spark

import org.apache.spark.sql.DataFrame在我的scala文件中,而不是sbt用来编译,错误是object DataFrame is not a member of package org.apache.spark.sql

在Internet上搜索了一些解决方案,看来问题是星火版本太旧了。但是我使用的是最新版本(2.1.1),所以很奇怪。

在REPL中,当I时import org.apache.spark.sql.DataFrame,没有错误。

我的功能是这样的:

def test(df: DataFrame): Unit={
    ....
}
Run Code Online (Sandbox Code Playgroud)

当我在REPL中定义此函数时,就可以了,但是当我使用sbt进行编译时,错误为not found: type DataFrame

我的build.sbt:

name := "Hello"

version := "1.0"

scalaVersion := "2.11.8"

libraryDependencies += "org.apache.spark" %% "spark-core" % "2.1.1"
Run Code Online (Sandbox Code Playgroud)

有人可以帮助我解决此问题吗?谢谢。

Sha*_*ala 6

您需要 spark-core 和 spark-sql 才能使用 Dataframe

libraryDependencies ++= Seq(
// https://mvnrepository.com/artifact/org.apache.spark/spark-core_2.11
  "org.apache.spark" %% "spark-core" % "2.1.1",
// https://mvnrepository.com/artifact/org.apache.spark/spark-sql_2.11
  "org.apache.spark" %% "spark-sql" % "2.1.1"
) 
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!