2012-03-25 13 views
7

के लिए संदर्भ निर्दिष्ट करने से पहले मैं स्कूबी या स्क्रंच के साथ खेलने में कूदने से पहले, मैंने सोचा था कि मैं केवल हाडोप (0.20.1) के जावा बाइंडिंग का उपयोग करके वर्डकाउंट को स्कैला (2.9.1) पर पोर्ट करने का प्रयास करूंगा।स्कैला/हाडोप: रेड्यूसर

मूल रूप से, मैं था:

class Map extends Mapper[LongWritable, Text, Text, IntWritable] { 
    @throws[classOf[IOException]] 
    @throws[classOf[InterruptedException]] 
    def map(key : LongWritable, value : Text, context : Context) { 
    //... 

कौन सा ठीक संकलित है, लेकिन मुझे एक रनटाइम त्रुटि दिया:

java.io.IOException: Type mismatch in key from map: expected org.apache.hadoop.io.Text, recieved org.apache.hadoop.io.LongWritable 

थोड़ा चारों ओर देखने के बाद, मैं पता लगा है कि यह था, क्योंकि मैं 'नहीं था उचित map विधि को परिभाषित नहीं किया जाना चाहिए (override की कमी से बंद कर दिया जाना चाहिए था), इसलिए मैंने इसे निर्धारित किया:

override def map(key : LongWritable, value : Text, 
    context : Mapper[LongWritable, Text, Text, IntWritable]#Context) { 

और voila, कोई रनटाइम त्रुटि नहीं।

लेकिन फिर मैंने नौकरी के आउटपुट को देखा, और महसूस किया कि मेरा reducer दौड़ नहीं रहा था।

तो मैं अपने कम करने को देखा, और पाया है reduce हस्ताक्षर मेरी नक्शाकार रूप में एक ही समस्या थी:

class Reduce extends Reducer[Text, IntWritable, Text, IntWritable] { 
    @throws[classOf[IOException]] 
    @throws[classOf[InterruptedException]] 
    def reduce(key : Text, value : Iterable[IntWritable], context : Context) { 
    //... 

तो मैं पहचान reduce बेमेल की वजह से किया जा रहा था अनुमान लगाया।

लेकिन जब मैं reduce के हस्ताक्षर को सही करने का प्रयास किया:

override def reduce(key: Text, values : Iterable[IntWritable], 
    context : Reducer[Text, IntWritable, Text, IntWritable]#Context) { 

अब मैं एक संकलक त्रुटि मिली:

[ERROR] /path/to/src/main/scala/WordCount.scala:32: error: method reduce overrides nothing 
[INFO]  override def reduce(key: Text, values : Iterable[IntWritable], 

तो मुझे यकीन है कि मैं गलत क्या कर रहा नहीं हूँ।

+0

और कम हस्ताक्षर क्या होना चाहिए? –

+0

@ डैनियलसी। सोब्राल: यह मेरा सवाल है। – rampion

उत्तर

11

पहली नज़र में, सुनिश्चित करें कि मूल्य जावा हैं। Lang.Iterable, स्कैला Iterable नहीं। या तो java.lang.Iterable आयात करें, या:

override def reduce(key: Text, values : java.lang.Iterable[IntWritable], context : Reducer[Text, IntWritable, Text, IntWritable]#Context) 
+2

यह बिल्कुल सही है। उदाहरण के लिए यहां देखें: https://bitbucket.org/jasonbaldridge/fogbow/src/6c24fb2afda4/src/main/scala/fogbow/example/WordCount.scala – dhg

संबंधित मुद्दे