나는 스칼라에서 스칼라를 사용하여 간단한 단어 개수를 실행하려고합니다. 그러나이 두 가지 오류가 발생합니다. 비교적 스칼라에 익숙하지 않으며 알아낼 수 없습니다.오류 : ')'예상 '하지만'(찾을 수 있습니다.
내가 실행하려고 코드는
error: ')' expected but '(' found.
println("sparkcontext created")
^
error: ';' expected but 'val' found.
val lines = sc.textFile(inputFile)
^
, 내가 그것을 알아낼 수. 내가 스칼라 구문에 대한 몇 가지 문서를 확인 않았지만이 문제를 이해하지 못하는되지 않았습니다
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.spark.SparkConf
object SparkWordCount
{
def main(args: Array[String])
{
//checking to see if the user has entered all the required args
if (args.length < 2)
{
System.err.println("Usage: <Input_File> <Output_File>")
System.exit(1)
}
val inputFile = args(0)
val outputFile = args(1)
// Here we create a new SparkContext instance called sc.
val sc = new SparkContext(spark://hdn1001.local:7077, "Scala Word Count",System.getenv("SPARK_HOME"), SparkContext.jarOfClass(this.getClass))
println("sparkcontext created")
// Input File
println("Parsing InputFile")
val lines = sc.textFile(inputFile)
println("Parsing InputFile completed")
// split each document into words
val words = lines.flatMap(line => line.split(" "))
println("Split each line of the InputFile into words")
//Count the occurrence of each word
val result = words.map(word => (word, 1))
.reduceByKey((x,y) => x+y)
println("WordCount completed")
// save the output to a file
result.saveAsTextFile(outputFile)
}
}
.
balaji에게 감사드립니다. 그 문제를 해결하십시오.
내가 인수 마스터에 대한 따옴표를 넣어 두 오류를 해결하기 위해 관리 않았다 발 사우스 캐롤라이나 = 새로운 SparkContext을 보일 것입니다 ("스파크 : //hdn1001.local : 7077", " – SarangArd