sc.textFile无法解析textFile上的符号

时间:2016-09-21 09:37:13

标签: scala intellij-idea apache-spark sbt

我正在使用IntelliJ进行scala 下面是我的代码:

import org.apache.spark.SparkConf
import org.apache.spark.sql._
import org.apache.spark.sql.types._
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
object XXXX extends App{

  val sc = new SparkConf()
  val DataRDD = sc.textFile("/Users/itru/Desktop/XXXX.bz2").cache()
}

我的build.sbt文件包含以下内容:

name := "XXXXX"
version := "1.0"
scalaVersion := "2.11.8"
libraryDependencies ++= Seq("org.apache.spark" %% "spark-core" % "1.5.2" %"provided",
"org.apache.spark" %% "spark-sql" % "1.5.2" % "provided")

已下载软件包,但我仍然看到错误"无法解析textFile上的符号"我错过了任何库依赖

1 个答案:

答案 0 :(得分:2)

您尚未初始化SparkContext

val sparkConf = new SparkConf()
val sc = new SparkContext(sparkConf)

val dataRDD = sc.textFile("/Users/itru/Desktop/XXXX.bz2").cache()