【发布时间】:2015-12-16 06:58:07
【问题描述】:
我有以下算法按字母顺序对数据进行排序
public void setup(Context context) throws IOException,
InterruptedException {
conf = context.getConfiguration();
caseSensitive = conf.getBoolean("amasort.case.sensitive", true);
}
@Override
public void map(Object key, Text value, Context context
) throws IOException, InterruptedException {
String line = (caseSensitive) ? value.toString() : value.toString().toLowerCase();
word.set(line+"_"+key.toString());
context.write(word, one);
System.out.println("key:"+key.toString()+";value:"+value.toString());
}
}
public static class ForwardReducer
extends Reducer<Text,NullWritable,Text,NullWritable> {
private NullWritable result = NullWritable.get();
public void reduce(Text key, Iterable<NullWritable> values,
Context context
) throws IOException, InterruptedException {
String originalWord = key.toString();
originalWord = originalWord.substring(0, originalWord.lastIndexOf("_"));
key.set(originalWord);
context.write(key, result);
}
}
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
GenericOptionsParser optionParser = new GenericOptionsParser(conf, args);
String[] remainingArgs = optionParser.getRemainingArgs();
Job job = Job.getInstance(conf, "word sort");
job.setJarByClass(AmaSort.class);
job.setMapperClass(LineMapper.class);
// job.setCombinerClass(ForwardReducer.class);
job.setReducerClass(ForwardReducer.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(NullWritable.class);
FileInputFormat.addInputPath(job, new Path(remainingArgs[0]));
FileOutputFormat.setOutputPath(job, new Path(remainingArgs[1]));
System.exit(job.waitForCompletion(true) ? 0 : 1);
我尝试使用此算法对包含 (@xxxxxxx, 0,tcp,xx,1,1,1,2,4,5,....) 的 mydata 集进行排序,但输出所有以 @ 开头的行都被删除和数据行结构 0,tcp,x1x1,1,114,.... 被修改,我只想用这个特定的字符 (@) 对我的数据集进行排序,所有行在文件的第一个以 @ 开头,其余的保持相同的结构。 任何人都可以帮我修改这个算法吗?
【问题讨论】:
标签: sorting hadoop mapreduce dataset