2014-10-29 142 views
0

我已經使用try catch作爲我的mapreduce代碼的一部分。我在下面的代碼中基於COUNT減少了我的值。我我如何終止使用該代碼的工作在以下終止scala程序?

class RepReducer extends Reducer[NullWritable, Text, Text, IntWritable] { 
    override def reduce(key: NullWritable, values: Iterable[Text], context: Reducer[NullWritable, Text, Text, IntWritable]#Context): Unit = { 
    val count = values.toList.length 
    if (count == 0){ 
     try { 
     context.write(new Text("Number of tables with less than 40% coverage"), new IntWritable(count)) 
     } catch { 
     case e: Exception => 
      Console.err.println(" ") 
      e.printStackTrace() 
     } 
    } 
    else 
    { 
     System.out.println("terminate job") //here i want to terminate if count is not equal to 0 
    } 
    } 
} 
+0

'sys.exit()' http://www.scala-lang.org/api/current/index.html#[email protected](status:Int):Nothing – lea 2014-10-29 15:05:18

+2

'sys.exit ()',雖然技術上這個問題的答案很少是正確的行爲。也許在Hadoop中,但我認爲我們需要更多的細節來弄清楚這是否是XY問題。 – 2014-10-29 15:13:23

回答

0

覺得你還是需要調用context.write返回控制返回到Hadoop的,即使你決定在「其他」跳過某些數據。