我应该如何编译这个火花示例?

时间:2013-02-01 04:39:49

标签: scala apache-spark

我是Spark的新手,我实际上正在运行spark网站上给出的示例。

/*** SimpleJob.scala ***/
import spark.SparkContext
import SparkContext._

object SimpleJob extends Application {
  val logFile = "//var//log//syslog" // Should be some file on your system
  val jarName:Seq[String] = "target//scala-2.9.2//simple-project_2.9.2-1.0.jar"
  val sc = new SparkContext("local", "Simple Job", "/home/subodh/Downloads/spark-0.6.1/bin",jarName)
  val logData = sc.textFile(logFile, 2).cache()
  val numAs = logData.filter(line => line.contains("a")).count()
  val numBs = logData.filter(line => line.contains("b")).count()
  println("Lines with a: %s, Lines with b: %s".format(numAs, numBs))
}

当我使用sbt package命令编译它时,它会出现以下错误:

[error] /home/subodh/Downloads/spark-0.6.1/example/src/main/scala/SimpleJob.scala:7: type mismatch;
**[error]  found   : java.lang.String("target//scala-2.9.2//simple-project_2.9.2-1.0.jar")
[error]  required: Seq[String]**
[error]   val jarName:Seq[String] = "target//scala-2.9.2//simple-project_2.9.2-1.0.jar"
[error]                             ^
[error] one error found
[error] {file:/home/subodh/Downloads/spark-0.6.1/example/}default-9e9e7d/compile:compile: Compilation failed
[error] Total time: 3 s, completed Jan 31, 2013 11:31:21 PM

对此方面的任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:1)

jarName被声明为Seq[String]类型,但您为其提供了String“target // scala-2.9.2 // simple-project_2.9.2-1.0.jar”。将值更改为Seq("target//scala-2.9.2//simple-project_2.9.2-1.0.jar")会修复它。

scala> val jarName:Seq[String] = Seq("target//scala-2.9.2//simple-project_2.9.2-1.0.jar")
jarName: Seq[String] = List(target//scala-2.9.2//simple-project_2.9.2-1.0.jar)