我想在reduce函数的内容之前给输出文件写一个标题。我该怎么做?
这是我的map和reduce函数-
public static class MapForWordCountWithoutWorld extends Mapper<LongWritable, Text, Text, IntWritable> {
static Date lastDate = new Date(120, 4, 8);
static Date ignoreDate = new Date(119, 12, 31);
public void map(LongWritable key, Text value, Context con) throws IOException, InterruptedException {
String line = value.toString();
String[] words = line.split(",");
if (words[0].equals("date")) {
return;
}else if(!words[1].toLowerCase().equals("world")){
try {
Date date1 = new SimpleDateFormat("yyyy-MM-dd").parse(words[0]);
if(date1.getYear() > 119) {
if (date1.before(lastDate) || date1.equals(lastDate)) {
Text outputKey = new Text("Infected Population");
IntWritable outputValue = new IntWritable(new Integer(words[2]));
con.write(outputKey, outputValue);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
public static class ReduceForWordCount extends Reducer<Text, IntWritable, Text, IntWritable> {
public void reduce(Text word, Iterable<IntWritable> values, Context con)
throws IOException, InterruptedException {
int sum = 0;
for (IntWritable value : values) {
sum += value.get();
}
con.write(word, new IntWritable(sum));
}
}
现在,我只得到键值对。但无法在输出文件中添加标题
暂无答案!
目前还没有任何答案,快来回答吧!