MapReduce不仅可以处理文本数据,还可以处理二进制数据。
Hadoop顺序文件存储格式是二进制的键-值对序列,使用顺序文件作为MapReduce的输入,可以使用SequenceFileInputFormat。键-值对是由顺序文件格式决定,只需要保证map的输入格式正确,例如顺序文件的格式是InWritable-Intwritable,那么Mapper的输入格式也一样。
1、
MaxTempMapper
package hadoop.mr.sequenfileinputformat;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapreduce.Mapper;
import java.io.IOException;
/**
* MaxTempMapper
*/
public class MaxTempMapper extends Mapper<IntWritable, IntWritable, IntWritable,IntWritable> {
protected void map(IntWritable key, IntWritable value, Context context) throws IOException, InterruptedException {
context.write(key, value);
}
}
2、MaxTempReducer