-1
私は、販売されているすべてのTVユニットの出現を見つけるためのmapreduceプログラムを書こうとしています。 I/Pが サムスンEX- |オプティマ| 14 |マドヤプラデシュ| 132401 | 14200 オナイダ|明晰| 18 |ウッタルプラデシ| 232401 | 16200 赤い|まとも| 16 |ケララ| 922401 | 12200 溶岩|注意| 20 |アッサム| 454601 | 24200 禅|スーパー| 14 |マハラシュトラ| 619082 | 9200以下mapreduceのテキストファイルから文字列を(|)で分割する方法は?
は私が Mapper-
public class TotalUnitMapper extends Mapper<LongWritable,Text,Text,IntWritable> {
Text tvname;
//IntWritable unit;
public void setup(Context context){
tvname = new Text();
// unit = new IntWritable();
}
public void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException{
String[] lineArray2 = value.toString().split("|");
if(!lineArray2[0].contains("NA") || (!lineArray2[1].contains("NA"))){
tvname.set((lineArray2[0]));
IntWritable unit = new IntWritable(1);
context.write(tvname,unit);
}
}}
Reducer- パブリッククラスTotalUnitReducerがリデューサーを拡張しwritten-ているMapReduceのコードです{
public void reduce(Text tvname, Iterable<IntWritable> values, Context context)
throws IOException,InterruptedException{
int sum = 0;
for (IntWritable value : values){
sum+= value.get();
}
context.write(tvname, new IntWritable(sum));
}}
Driver-
public class TotalUnit {
public static void main(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = new Job(conf, "Assignment 3.3-2");
job.setJarByClass(TotalUnit.class);
job.setMapOutputKeyClass(Text.class);
job.setMapOutputValueClass(IntWritable.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
job.setMapperClass(TotalUnitMapper.class);
job.setReducerClass(TotalUnitReducer.class);
job.setNumReduceTasks(2);
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job,new Path(args[1]));
job.waitForCompletion(true);
}}
テレビ名の最初の文字が印刷され得ているthis-
A 1
O 4
S 7
L 3
N 1
Z 2
のみ、私はなぜわからないように私はO/Pを取得していますが。スプリットで何か問題がありますか? 私はHadoopの初心者です。 ありがとうございます。