scala mapreduce wordcount程序

px9o7tmv  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(282)

我为字数计算写了这个scala程序。主要课程如下

object aaa{
  def main(args:Array[String]) : Int = {
    val conf = new Configuration()
    val otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs
    if (otherArgs.length != 2) {
      println("Usage: wordcount <in> <out>")
      return 2
    }
    val job = new Job(conf, "word count")
    job.setJarByClass(classOf[TokenizerMapper])
    job.setMapperClass(classOf[TokenizerMapper])
    job.setCombinerClass(classOf[IntSumReducer])
    job.setReducerClass(classOf[IntSumReducer])
    job.setOutputKeyClass(classOf[Text])
    job.setOutputValueClass(classOf[IntWritable])
    FileInputFormat.addInputPath(job, new Path(args(0)))
    FileOutputFormat.setOutputPath(job, new Path((args(1))))
    if (job.waitForCompletion(true)) 0 else 1
 }
}

这里我得到一个警告:“aaa有一个参数类型为array[string]的main方法,但是hadooop.aaa将不是一个可运行的程序。原因:main方法必须有精确的签名(array[string])单位。
如何解决这个问题?我也不能在runconfiguration中加载这个类。请帮我把这个修好。

qq24tv8q

qq24tv8q1#

它可能对你使用 : Int 你宣布的主要地点。
尝试将main声明替换为

def main(args:Array[String]) : Unit = {
    //...
}

对于每个带有退出代码的返回,用调用 System.exit(1) 或者 System.exit(0) 视情况而定。
我相信你在寻找一个更优雅的终止,但那应该是你想要的。

相关问题