ich für eine bestimmte Zeichenfolge in einer Textdatei und zählt diese bestimmten Zeichenfolge zu suchen bin versucht, und ich schrieb folgenden Code und jetzt bin ich nicht sicher, was ich soll hier freundlich antworten ändern:Ausgabe in Map Reduce IOException
HierError: 16/04/29 04:30:27 INFO mapreduce.Job: Job job_1461630807194_0010 running in uber
mode : false 16/04/29 04:30:27 INFO mapreduce.Job: map 0% reduce 0% 16/04/29 04:34:08 INFO mapreduce.Job: map 100% reduce 0% 16/04/29 04:34:15 INFO mapreduce.Job: Task Id : attempt_1461630807194_0010_m_000
000_0, Status : FAILED Error: java.io.IOException: Type mismatch in key from map: expected org.apache.h
adoop.io.Text, received org.apache.hadoop.io.LongWritable at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.collect(MapTask.java :1072)
ist der Code:
Mein Mapper Klasse:
package Receipt;
import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
public class ReceiptMapper extends Mapper<LongWritable,Text,Text,Text>
{
public static class Stringmap extends Mapper<LongWritable, Text, Text, IntWritable> {
public void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {
String str = value.toString();
String findStr = "not created";
int lastIndex = 0;
int count = 0;
while (lastIndex != -1) {
lastIndex = str.indexOf(findStr, lastIndex);
if (lastIndex != -1) {
count++;
lastIndex += findStr.length();
}
}
if (str.contains(findStr)) {
context.write(new Text(findStr), new IntWritable(count));
}
}
}
}
public class ReceiptReducer extends Reducer<Text, IntWritable, Text, IntWritable>
{
public void reduce(Text key, Iterable<IntWritable> values,Context context) throws IOException, InterruptedException {
int sum = 0;
for (IntWritable val : values)
{
sum += val.get();
}
context.write(key, new IntWritable(sum));
}
}
public class ReceiptCount {
@SuppressWarnings("deprecation")
public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException{ {
// TODO Auto-generated method stub
Configuration conf = new Configuration();
Job job = new Job(conf, "Stringfound");
job.setJarByClass(ReceiptCount.class);
job.setMapperClass(ReceiptMapper.class);
job.setReducerClass(ReceiptReducer.class);
job.setMapOutputKeyClass(LongWritable.class);
job.setMapOutputValueClass(LongWritable.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(IntWritable.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
//setMapOutputKeyClass();
//setMapOutputValueClass();
Path outputDir = new Path(args[1]);
outputDir.getFileSystem(conf).delete(outputDir, true);
FileOutputFormat.setOutputPath(job, outputDir);
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
}
Ich bin mir nicht sicher, wo ich falsch liege, es ist alles, was ich IntWrittible und LongWritable versuchte, aber nicht in der Lage, damit fertig zu werden. Und MapReduce ist neu für mich. – george
Mein Ziel ist es, eine Zeichenfolge in einer Textdatei zu finden, die durch "." Zum Beispiel ist Textdatei wie "abc.def.naha.gsgsfs.not created", also versuche ich zu suchen, wie viele nicht erstellte dort sind. – george