2013-06-04 5 views
13

Sto cercando di modificare un problema esistente per soddisfare le mie esigenze ..tipo non corrispondente in valore da mappa: atteso org.apache.hadoop.io.NullWritable, org.apache.hadoop.io.Text ricevuto

Fondamentalmente ingresso è semplice testo I processi iT e passo coppia chiave/valore di riduttore e creo un jSON .. quindi non v'è la chiave, ma nessun valore così mapper:

ingresso: testo/testo

uscita: Testo/Testo

Reducer: Testo/Testo

uscita: Testo/Nessuno

mie firme sono i seguenti:

public class AdvanceCounter { 
/** 
* The map class of WordCount. 
*/ 
public static class TokenCounterMapper 
    extends Mapper<Object, Text, Text, Text> { // <--- See this signature 

    public void map(Object key, Text value, Context context) // <--- See this signature 
     throws IOException, InterruptedException { 

    context.write(key,value); //both are of type text OUTPUT TO REDUCER 
    } 
} 
    public static class TokenCounterReducer 
    extends Reducer<Text, Text, Text, **NullWritable**> { // <--- See this signature Nullwritable here 
    public void reduce(Text key, Iterable<Text> values, Context context) // <--- See this signature 
     throws IOException, InterruptedException { 


     for (Text value : values) { 
      JSONObject jsn = new JSONObject(); 
      //String output = ""; 
      String[] vals = value.toString().split("\t"); 
      String[] targetNodes = vals[0].toString().split(",",-1); 
      try { 
       jsn.put("source",vals[1]); 
       jsn.put("targets",targetNodes); 
       context.write(new Text(jsn.toString()),null); // no value 
      } catch (JSONException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 

     } 


    } 
} 
public static void main(String[] args) throws Exception { 
    Configuration conf = new Configuration(); 
    String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); 
    Job job = new Job(conf, "Example Hadoop 0.20.1 WordCount"); 

    // ... 
    // 
    job.setOutputValueClass(NullWritable.class); 
    FileInputFormat.addInputPath(job, new Path(otherArgs[0])); 
    FileOutputFormat.setOutputPath(job, new Path(otherArgs[1])); 
    System.exit(job.waitForCompletion(true) ? 0 : 1); 
} 

} 

Ma d'esecuzione sto ottenendo questo errore:

13/06/04 13:08:26 INFO mapred.JobClient: Task Id : attempt_201305241622_0053_m_000008_0, Status : FAILED 
java.io.IOException: Type mismatch in value from map: expected org.apache.hadoop.io.NullWritable, recieved org.apache.hadoop.io.Text 
    at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.collect(MapTask.java:1019) 
    at org.apache.hadoop.mapred.MapTask$NewOutputCollector.write(MapTask.java:691) 
    at org.apache.hadoop.mapreduce.TaskInputOutputContext.write(TaskInputOutputContext.java:80) 
    at org.sogou.Stinger$TokenCounterMapper.map(Stinger.java:72) 
    at org.sogou.Stinger$TokenCounterMapper.map(Stinger.java:1) 
    at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:144) 
    at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:764) 
    at org.apache.hadoop.mapred.MapTask.run(MapTask.java:370) 
    at org.apache.hadoop.mapred.Child$4.run(Child.java:255) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at javax.security.auth.Subject.doAs(Subject.java:396) 
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1093) 
    at org.apache.hadoop.mapred.Child.main(Child.java:249) 

risposta

38

si rifugio 't specificato i tipi di output della mappa, quindi sta prendendo lo stesso come impostato per il riduttore, che sono Text e NullWritable che non è corretto per il tuo mapper . Si dovrebbe fare quanto segue per evitare qualsiasi confusione è meglio specificare tutte le tipologie sia per mapper e riduttore:

job.setMapOutputKeyClass(Text.class); 
job.setMapOutputValueClass(Text.class); 
job.setOutputKeyClass(Text.class); 
job.setOutputValueClass(NullWritable.class); 
+0

Grazie mille :) – Fraz

+0

Questo funziona perfettamente. –

Problemi correlati