2014-11-15 2 views
-9

나는 스칼라에서 스칼라를 사용하여 간단한 단어 개수를 실행하려고합니다. 그러나이 두 가지 오류가 발생합니다. 비교적 스칼라에 익숙하지 않으며 알아낼 수 없습니다.오류 : ')'예상 '하지만'(찾을 수 있습니다.

내가 실행하려고 코드는

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에게 감사드립니다. 그 문제를 해결하십시오.

+0

내가 인수 마스터에 대한 따옴표를 넣어 두 오류를 해결하기 위해 관리 않았다 발 사우스 캐롤라이나 = 새로운 SparkContext을 보일 것입니다 ("스파크 : //hdn1001.local : 7077", " – SarangArd

답변

1

그냥 스파크 마스터 URL을 큰 따옴표로 묶습니다. 가 따라서는, 같은

val sc = new SparkContext("spark://hdn1001.local:7077", "Scala Word Count",System.getenv("SPARK_HOME"), SparkContext.jarOfClass(this.getClass)) 
+0

'sparkContext를 val sc = new SparkContext로 변경했습니다 ("spark : //hdn1001.local : 7077", "Scala Word Count", System.getenv ("SPARK_HOME"), SparkContext.jarOfClass 단어 개수 ", System.getenv ("SPARK_HOME "), SparkContext.jarOfClass (this.getClass) .toSeq)'그리고 그것은 효과가있었습니다. – SarangArd

+0

'toSeq'는'jarOfClass'가'Option [String]'을 반환하지만'SparkContext'는'Seq [String]'을 요구하기 때문에 필요합니다. 이 동작은 이전 버전의 Spark에서 변경되었습니다. https://issues.apache.org/jira/browse/SPARK-1496을 참조하십시오. – DNA