2014-12-30 5 views
1

매퍼에서 TwoDArrayWritable을 방출하고 있습니다. 기본 생성자를 만들기 위해 TwoDArrayWritable을 확장하는 클래스를 구현했습니다. 하지만 방출하려고 할 때 다음 예외를 제공합니다.Hadoop - TwoDArrayWritable을 내보내는 방법

Error: java.lang.RuntimeException: java.lang.InstantiationException: org.apache.hadoop.io.TwoDArrayWritable 
     at org.apache.hadoop.io.TwoDArrayWritable.readFields(TwoDArrayWritable.java:75) 
     at org.apache.hadoop.io.serializer.WritableSerialization$WritableDeserializer.deserialize(WritableSerialization.java:71) 

TwoDArrayWritable을 어떻게 방출합니까? 도움이 필요해. 여기

가 TwoDArrayWritable 확장 클래스이다 감속기 여기

public class JaccardMapper extends Mapper<LongWritable, Text, IntTextPair, TwoDArrayWritables> { 

    Hashtable movieInfo = new Hashtable<String, String>(); 
    String[] genres, actors, entities; 
    String[] attributes = new String[] {"genre", "actors", "directors", "country", "year", "ratings"}; 
    double p,q,r,s; 
    double result = 0.0; 
    String input[] = null; 
    Set<String> keys; 

    TwoDArrayWritables array2d = new TwoDArrayWritables(); 
    //TwoDArrayWritable array2d = new TwoDArrayWritable(IntWritable.class); 

    IntWritable[][] jaccard = new IntWritable[2][]; 
    //int[][] jaccard = new int[2][]; 


    public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException 
    { 

     p = 0; 
     q = 0; 
     r = 0; 
     s = 0; 

     input = value.toString().toLowerCase().split(","); 
     keys = movieInfo.keySet(); 


     //the jaccards 2d array column length depends on the user input best case is 6 but the worst case depends on the sub attributes count like more than one actor/director/genre/country. 
     int columnlength = input[1].split("\\|").length + input[2].split("\\|").length + input[3].split("\\|").length + input[4].split("\\|").length + 2; 
     jaccard = new IntWritable[2][columnlength]; 
     for (int i = 0; i < jaccard.length; i++) 
     { 
      for (int j = 0; j < jaccard[i].length; j++) 
      { 
       jaccard[i][j] = new IntWritable(0); 
      } 
     } 

     if (input.length > 0) 
     { 
      //iterate through the dataset in cache 
      for(String keyy : keys) 
      { 
       //iterate to user's input attributes 
       for (int attribute = 1; attribute < attributes.length; attribute++) 
       { 
        if (!input[attribute].equals("-")) 
        { 
         entities = input[attribute].toLowerCase().split("\\|"); 
         int subattributecount = 0; 

         for(String entity : entities) 
         { 

           subattributecount += 1; 
         } 
        } 
       } 
       IntTextPair pair = new IntTextPair(Integer.parseInt(input[0].toString()), movieInfo.get(keyy).toString()); 

       array2d.set(jaccard); 
           context.write(pair, array2d); 
      } 


     } 

} 
} 

된다 : 여기서

public class TwoDArrayWritables extends TwoDArrayWritable 
{ 
    public TwoDArrayWritables() { 
     super(TwoDArrayWritable.class); 

    } 


    public TwoDArrayWritables(Class valueClass) { 
     super(valueClass); 
     // TODO Auto-generated constructor stub 
    } 

는 매퍼 공용 클래스 JaccardReducer는 {

double p,q,r,s; 
double result = 0.0; 
//IntWritable[][] jaccard = null; 
IntWritable[][] jaccard; 
int temp1 = 0, temp2 = 0; 

//Jaccard distance 1.0 emplies that the user's criteria doesn't meet at all 
public static final double nonacceptvalue = 1.0; 


    public void reduce(IntTextPair key, Iterable<TwoDArrayWritables> values, Context context) throws IOException, InterruptedException 
    { 

     IntDoublePair pair = new IntDoublePair(key.getFirst().get(), Double.parseDouble("110.00")); 
     for (TwoDArrayWritable value : values) 
     { 
      if (value != null) 
      { 
       context.write(pair, new Text("Is not null")); 
      } 
      else 
      { 
       context.write(pair, new Text("Is null")); 
      } 
     } 
} 
} 

답변

1

감속기 확장 기본 생성자에서 지정한 클래스 (super) 전체 클래스 자체가 아닌 값의 클래스 여야합니다. 그래서 당신이 원할 것입니다 :

public TwoDArrayWritables() { 
    super(IntWritable.class); 

} 
+0

실수를 정정 해 주셔서 감사합니다. :) – user1584253