2016-01-04 47 views
0
package Sort; 
    import java.io.IOException; 
    import org.apache.hadoop.io.DoubleWritable; 
    import org.apache.hadoop.io.LongWritable; 
    import org.apache.hadoop.io.Text; 
    import org.apache.hadoop.mapreduce.Mapper; 
    public class sortmapper extends     Mapper<LongWritable,Text,Text,DoubleWritable> { 
     public void map(Text key, Iterable<DoubleWritable> value, Context       context) throws IOException, InterruptedException { 
      String line = value.toString(); 
      String subId = line.substring(15, 26); 
      Double bytes = Double.parseDouble(line.substring(45, 56)); 
      if (bytes == null) 
       bytes = 0.0; 
      context.write(new Text(subId),new DoubleWritable(bytes)); 
     } 
    } 

這是我寫映射器的方法,但我m到處上述錯誤。在鍵的類型不匹配從圖:預期org.apache.hadoop.io.Text,接收org.apache.hadoop.io.LongWritable

+0

的可能的複製[從圖中關鍵類型不匹配:預計org.apache.hadoop.io.Text,收到org.apache.hadoop.io.LongWritable]( http://stackoverflow.com/questions/17262188/type-mismatch-in-key-from-map-expected-org-apache-hadoop-io-text-received-org) –

回答

0

的問題是在這裏:

public class sortmapper extends Mapper<LongWritable,Text,Text,DoubleWritable> { 
     public void map(Text key, Iterable<DoubleWritable> value, Context  

Mapper<LongWritable,Text,Text,DoubleWritable>

爲了您的映射器,輸入鍵和值是:

LongWritable and Text 

輸出鍵和值是:

Text and DoubleWritable 

和你map()簽名應該是:

public void map(LongWritable key, Text value, Context context) 
相關問題