2012-06-12 8 views
9

मैं जानना चाहता हूं कि आउटपुट कोलेक्टर का 'इंस्टेंस' आउटपुट मानचित्र फ़ंक्शन में उपयोग किया जाता है: output.collect (कुंजी, मान) यह-आउटपुट- कहीं भी महत्वपूर्ण मूल्य जोड़े संग्रहीत कर रहा है? भले ही यह reducer फ़ंक्शन पर निकल जाए, फिर भी यह एक मध्यवर्ती फ़ाइल होनी चाहिए, है ना? उन फाइलें क्या हैं? क्या वे प्रोग्रामर द्वारा दृश्यमान और निर्णय लेते हैं? क्या आउटपुटकी क्लास, और आउटपुट वैल्यू क्लासेस हैं जिन्हें हम मुख्य कार्य में इन स्टोरेज के स्थानों में निर्दिष्ट करते हैं? [Text.class और IntWritable.class]हडोप: आउटपुटकॉल्टर MapReduce के दौरान कैसे काम करता है?

मै मैड्रिडस में शब्द गणना उदाहरण के लिए मानक कोड दे रहा हूं, जिसे हम नेट में कई स्थानों पर पा सकते हैं।

public class WordCount { 

public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> { 
private final static IntWritable one = new IntWritable(1); 
private Text word = new Text(); 

public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException { 
String line = value.toString(); 
StringTokenizer tokenizer = new StringTokenizer(line); 
while (tokenizer.hasMoreTokens()) { 
word.set(tokenizer.nextToken()); 
output.collect(word, one); 
} 
} 
} 

public static class Reduce extends MapReduceBase implements Reducer<Text, IntWritable, Text, IntWritable> { 
public void reduce(Text key, Iterator<IntWritable> values, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException { 
int sum = 0; 
while (values.hasNext()) { 
sum += values.next().get(); 
} 
output.collect(key, new IntWritable(sum)); 
} 
} 

public static void main(String[] args) throws Exception { 
JobConf conf = new JobConf(WordCount.class); 
conf.setJobName("wordcount"); 

conf.setOutputKeyClass(Text.class); 
conf.setOutputValueClass(IntWritable.class); 

conf.setMapperClass(Map.class); 
conf.setCombinerClass(Reduce.class); 
conf.setReducerClass(Reduce.class); 

conf.setInputFormat(TextInputFormat.class); 
conf.setOutputFormat(TextOutputFormat.class); 

FileInputFormat.setInputPaths(conf, new Path(args[0])); 
FileOutputFormat.setOutputPath(conf, new Path(args[1]));  
JobClient.runJob(conf); 
} 
} 
+0

आप इन अस्थायी फ़ाइलों तक क्यों पहुंचना चाहते हैं? क्या आपके पास एक ऐसी चीज है जिसे आप प्राप्त करना चाहते हैं? या यह सिर्फ curisoity है? – adranale

+0

मैं इन अस्थायी फ़ाइलों का स्थान बदलना चाहता हूं। – catty

उत्तर

2

मेरा मानना ​​है कि वे अस्थायी स्थानों में संग्रहीत और डेवलपर के लिए उपलब्ध नहीं है, जब तक आप अपने खुद के वर्ग कि OutputCollector लागू करता है बनाने के कर रहे हैं।

मैं एक बार उन फ़ाइलों का उपयोग करने के लिए किया था और पक्ष प्रभाव फ़ाइलें बनाने के द्वारा समस्या का समाधान: http://hadoop.apache.org/common/docs/r0.20.2/mapred_tutorial.html#Task+Side-Effect+Files

+0

क्या किसी के पास आउटपुट कोलेक्टर के .collect() फ़ंक्शन के लिए कोड है? – catty

3

मानचित्र समारोह से उत्पादन अस्थायी मध्यवर्ती फ़ाइलें में संग्रहित है। इन फ़ाइलों को हडोप द्वारा पारदर्शी रूप से संभाला जाता है, इसलिए एक सामान्य परिदृश्य में, प्रोग्रामर को उस तक पहुंच नहीं होती है। यदि आप प्रत्येक मैपर के अंदर क्या हो रहा है, इसके बारे में उत्सुक हैं, तो आप संबंधित नौकरी के लिए लॉग की समीक्षा कर सकते हैं जहां आपको प्रत्येक मानचित्र कार्य के लिए लॉग फ़ाइल मिल जाएगी।

यदि आप नियंत्रित करना चाहते हैं कि अस्थायी फ़ाइलें कहां उत्पन्न की जाती हैं, और उनके पास पहुंच है, तो आपको अपना आउटपुट कोलेक्टर क्लास बनाना होगा, और मुझे नहीं पता कि यह कितना आसान है।

यदि आप स्रोत कोड को देखना चाहते हैं, तो आप इसे प्राप्त करने के लिए svn का उपयोग कर सकते हैं। मुझे लगता है कि यह यहां उपलब्ध है: http://hadoop.apache.org/common/version_control.html

0

इंटरमीडिएट, समूहीकृत आउटपुट हमेशा सेक्वेंसफाइल में संग्रहीत होते हैं। अनुप्रयोग निर्दिष्ट कर सकते हैं कि इंटरमीडिएट आउटपुट को संपीड़ित किया जाना चाहिए और कौन सी संपीड़न कोडेक्स को जॉबकॉन्फ़ के माध्यम से उपयोग किया जाना है।

http://hadoop.apache.org/docs/current/api/org/apache/hadoop/mapred/Mapper.html

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