Changes between Version 2 and Version 3 of waue/2009/0716


Ignore:
Timestamp:
Jul 16, 2009, 5:47:29 PM (15 years ago)
Author:
waue
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • waue/2009/0716

    v2 v3  
    44 原因:Type mismatch in key from map: expected org.apache.hadoop.io.LongWritable, recieved org.apache.hadoop.io.Text
    55
    6  Map的key從LongWritable 強制轉型到 String,似乎會遇到一些錯
     6 Map 的 key 從 longWritable 強制轉型到 String,似乎會遇到一些錯
    77
    88 * keyvalue.java
     
    2020public class keyvalue{
    2121        public static void main(String[] args) {
    22                 String[] argv = {"input","oh9","1","1"};
     22                String[] argv = {"input","output","1","1"};
    2323                args = argv;
    2424               
     
    5353
    5454{{{
    55 #!java
     55
    5656package nchc.keyvalue;
    5757
     
    8181
    8282{{{
    83 #!java
     83
    8484package nchc.keyvalue;
    8585
     
    106106}
    107107}}}
     108
     109----------
     110改成以下的map 與 reduce 檔就可以正常運作
     111
     112 * kvM.java
     113
     114{{{
     115#!java
     116package nchc.keyvalue;
     117
     118import java.io.IOException;
     119
     120import org.apache.hadoop.io.LongWritable;
     121import org.apache.hadoop.io.Text;
     122import org.apache.hadoop.mapred.MapReduceBase;
     123import org.apache.hadoop.mapred.Mapper;
     124import org.apache.hadoop.mapred.OutputCollector;
     125import org.apache.hadoop.mapred.Reporter;
     126
     127public class kvM extends MapReduceBase implements
     128                Mapper<LongWritable, Text, LongWritable, Text> {
     129
     130        public void map(LongWritable key, Text value,
     131                        OutputCollector<LongWritable, Text> output, Reporter report)
     132                        throws IOException {
     133                output.collect(key, value);
     134        }
     135
     136}
     137}}}
     138
     139 * kvR.java
     140
     141{{{
     142#!java
     143package nchc.keyvalue;
     144
     145import java.io.IOException;
     146import java.util.Iterator;
     147
     148import org.apache.hadoop.io.LongWritable;
     149import org.apache.hadoop.io.Text;
     150import org.apache.hadoop.mapred.MapReduceBase;
     151import org.apache.hadoop.mapred.OutputCollector;
     152import org.apache.hadoop.mapred.Reducer;
     153import org.apache.hadoop.mapred.Reporter;
     154
     155public class kvR extends MapReduceBase implements
     156                Reducer< LongWritable, Text, Text, Text> {
     157        public void reduce(LongWritable key, Iterator<Text> values,
     158                        OutputCollector<Text, Text> output, Reporter report)
     159                        throws IOException {
     160                while (values.hasNext()) {
     161                        Text keyv = new Text("< "+key+" , ");
     162                        Text val = new Text(values.next()+">");
     163                        output.collect(keyv, val);
     164                }
     165        }
     166}
     167}}}
     168
     169然而就看不到key被reduce起來
     170
     171 * output/part-00000
     172{{{
     173< 0 ,   This eBook is for the use of anyone anywhere at no cost and with>
     174< 0 ,   This eBook is for the use of anyone anywhere at no cost and with>
     175< 66 ,  almost no restrictions whatsoever.  You may copy it, give it away or>
     176< 66 ,  almost no restrictions whatsoever.  You may copy it, give it away or>
     177< 136 ,         re-use it under the terms of the Project Gutenberg License included>
     178< 136 ,         re-use it under the terms of the Project Gutenberg License included>
     179< 205 ,         with this eBook or online at www.gutenberg.net>
     180< 205 ,         with this eBook or online at www.gutenberg.org>
     181
     182.... (省略)
     183}}}