여기입니다 이해하지 : 나는 밖으로 내 코드를 주석 한내가받을 오류를 맵리 듀스 NPE
14/02/28 02:52:43 INFO mapred.JobClient: Task Id : attempt_201402271927_0020_m_000001_2, Status : FAILED
java.lang.NullPointerException
at org.apache.hadoop.mapred.MapTask$MapOutputBuffer.init(MapTask.java:843)
at org.apache.hadoop.mapred.MapTask.createSortingCollector(MapTask.java:376)
at org.apache.hadoop.mapred.MapTask.access$100(MapTask.java:85)
at org.apache.hadoop.mapred.MapTask$NewOutputCollector.<init>(MapTask.java:584)
at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:656)
at org.apache.hadoop.mapred.MapTask.run(MapTask.java:330)
at org.apache.hadoop.mapred.Child$4.run(Child.java:268)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAs(Subject.java:396)
at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1408)
at org.apache.hadoop.mapred.Child.main(Child.java:262)
기본적으로 전형적인 LongWritable 및 텍스트에 타고 나는 단지 출력 일정한 IntWritable 1과 빈 날씨 클래스 (사용자 정의 클래스) : 여기
public class Map extends Mapper<LongWritable, Text, IntWritable, Weather> {
private IntWritable id = new IntWritable(1);
private Weather we = new Weather();
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
//String s;
//String line = value.toString();
//int start[] = {0,18,31,42,53,64,74,84,88,103};
//int end[] = {6,22,33,44,55,66,76,86,93,108};
//if(line.length() > 108) {
// create the object to hold our data
// getStuff()
// parse the string
// push the object onto our data structure
context.write(id, we);
//}
}
내 R입니다 : 여기
내 매퍼 클래스입니다 educer : 여기
public class Reduce extends Reducer<IntWritable, Weather, IntWritable, Text> {
private Text text = new Text("one");
private IntWritable one = new IntWritable(1);
public void reduce(IntWritable key, Iterable<Weather> weather, Context context)
throws IOException, InterruptedException {
//for(Weather w : weather) {
// text.set(w.toString());
context.write(one, text);
}
}
내 주요입니다 : 여기
public class Skyline {
public static void main(String[] args) throws IOException{
//String s = args[0].length() > 0 ? args[0] : "skyline.in";
Path input, output;
Configuration conf = new Configuration();
conf.set("io.serializations", "org.apache.hadoop.io.serializer.JavaSerialization,"
+ "org.apache.hadoop.io.serializer.WritableSerialization");
try {
input = new Path(args[0]);
} catch(ArrayIndexOutOfBoundsException e) {
input = new Path("hdfs://localhost/user/cloudera/in/skyline.in");
}
try {
output = new Path(args[1]);
//FileSystem.getLocal(conf).delete(output, true);
} catch(ArrayIndexOutOfBoundsException e) {
output = new Path("hdfs://localhost/user/cloudera/out/");
//FileSystem.getLocal(conf).delete(output, true);
}
Job job = new Job(conf, "skyline");
job.setJarByClass(Skyline.class);
job.setOutputKeyClass(IntWritable.class);
job.setOutputValueClass(Weather.class);
job.setMapperClass(Map.class);
job.setReducerClass(Reduce.class);
job.setInputFormatClass(TextInputFormat.class);
job.setOutputFormatClass(TextOutputFormat.class);
FileInputFormat.addInputPath(job, input);
FileOutputFormat.setOutputPath(job, output);
try {
job.waitForCompletion(true);
} catch(InterruptedException e) {
System.out.println("Interrupted Exception");
} catch(ClassNotFoundException e) {
System.out.println("ClassNotFoundException");
}
}
}
내 일기 클래스의 샘플입니다 : 내 순발력 끝에 해요
public class Weather {
private in stationId;
public Weather(){}
public int getStation(){return this.stationID;}
public void setStation(int r){this.stationID = r}
//...24 additional things of ints, doubles and strings
}
. 이 시점에서 나는 아무것도하지 않고 여전히 오류를받는 프로그램 쉘을 가지고있다. 나는 Java Generics를 올바르게 사용하고 있는지 확인하기 위해 MapReduce 패러다임에 매우 익숙하다. 그러나이 프로그램은 MapReduce 튜토리얼 (https://hadoop.apache.org/docs/r1.2.1/mapred_tutorial.html#Walk-through)에서 변형 된 쉘이다.).
'날씨'클래스의 정의를 포함 할 수 있습니까? –
이것은 get/set 메서드가 25 개만있는 실제 간단한 클래스입니다. 생성자에서는 작업이 수행되지 않습니다. 그것은 프로그램 주위의 단일 스테이션에서 25 개의 날씨 변수를 이동하는 가장 쉬운 방법입니다. 위의 코드를 참조하십시오. – lilott8
Weather 클래스에서 org.apache.Hadoop.io.Writable을 구현하여 이것이 작동해야한다고 생각합니다. Writable 이외의 것을 전달하고 싶다면 훨씬 더 많은 사용자 정의 코드를 작성해야합니다. –