sequencefile文件的map输入
public class mapper extends Mapper <IntWritable, IntWritable,IntWritable, IntWritable>{
protected void map(IntWritable key,IntWritable value, Context context) throws IOException, InterruptedException {
context.write( key , value);
}
}
因为sequencefile本来就以k v 对的形式存储 所以可以直接读取k v对
wordcount
public class mapper extends Mapper <LongWritable, Text,Text, IntWritable>{
@Override
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
Text keyOut = new Text();
IntWritable valueOut = new IntWritable();
String[] arr = value.toString().split(" ");
for(String s : arr){
keyOut.set(s);
valueOut.set(1);
context.write(keyOut,valueOut);
}
}
}
wordcount读取的是文本文件 所以他的k 是文本文件首地址偏移量所以用longwritable型 v为文件的一行(以回车为结束符)
public class mapper extends Mapper <LongWritable, Text,IntWritable, IntWritable>{
protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
String line = value.toString();
String arr[] = line.split(" ");
context.write(new IntWritable(Integer.parseInt(arr[0])),new IntWritable(Integer.parseInt(arr[1])));
}
}
这是一个记录不同不同年代温度程序的map 他读取的文件也是文本文件以列如
1980 30
1997 40
的格式存储因为他也是文本文件所以kv值 也是 k 是文本文件首地址偏移量所以用longwritable型 v为文件的一行(以回车为结束符)然后将v通过以" "空格为切割点切割再将切割的字符串转换为intwritable型