2017-04-10 14 views
0

私は、以下のコードを実行して、2人の間の共通の友人を見つけようとしています。入力は次のようになりますhadoop mapreduceコモンフード還元剤流出

A : B C D 

B : A C D E 

C : A B D E 

D : A B C E 

E : B C D 

出力ファイルで出力を取得することができず、例外もありません。

以下の私のコードを見つけてください、

public class Friend { 
    public static class Mapperfriend extends Mapper<Object, Text, Text, Text>{ 


     private Text vendor = new Text(); 


     @Override 
     protected void map(Object key, Text value, Context context) throws IOException, InterruptedException { 
     StringTokenizer tokenizer = new StringTokenizer(value.toString(), "\n"); 
     String line = null; 
     String[] lineArray = null; 
     String[] friendArray = null; 
     String[] tempArray = null;  



     while(tokenizer.hasMoreTokens()){ 
     line = tokenizer.nextToken(); 
     lineArray = line.split(":"); 
     friendArray = lineArray[1].split(" "); 
     tempArray = new String[2]; 
     for(int i = 0; i < friendArray.length; i++){ 
       tempArray[0] = friendArray[i]; 
       tempArray[1] = lineArray[0]; 
       Arrays.sort(tempArray); 
       context.write(new Text(tempArray[0] + " " + tempArray[1]), new Text(lineArray[1])); 
     } 

     } 


    }} 

    public static class ReducerFriend extends Reducer<Text,Text,Text,Text>{ 

     @Override 
     protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException { 


     Text[] texts = new Text[2]; 
       int index = 0; 


       for(Text val: values) 
       { 
         texts[index++] = new Text(val); 
       } 
       String[] list1 = texts[0].toString().split(" "); 
       String[] list2 = texts[1].toString().split(" "); 
       List<String> list = new LinkedList<String>(); 
       for(String friend1 : list1){ 
         for(String friend2 : list2){ 
           if(friend1.equals(friend2)){ 
             list.add(friend1); 
           } 
         } 
       } 
       StringBuffer sb = new StringBuffer(); 
       for(int i = 0; i < list.size(); i++){ 
         sb.append(list.get(i)); 
         if(i != list.size() - 1) 
           sb.append(" "); 
       } 
       context.write(key, new Text(sb.toString())); 
     } 
    } 




    /** 
    * @param args the command line arguments 
    */ 
    public static void main(String[] args) throws Exception { 
     // TODO code application logic here 

     Configuration conf = new Configuration(); 
     Job job = Job.getInstance(conf, "Friends"); 
     job.setJarByClass(Friend.class); 
     job.setMapperClass(Mapperfriend.class); 
     job.setReducerClass(ReducerFriend.class); 
     job.setOutputKeyClass(Text.class); 
     job.setOutputValueClass(Text.class); 
     FileInputFormat.addInputPath(job, new Path(args[0])); 
     FileOutputFormat.setOutputPath(job, new Path(args[1])); 
     System.exit(job.waitForCompletion(true) ? 0 : 1); 
    } 



} 

答えて

0

マッパークラスは、最初から全体の鍵を放出されます。配列を取り出す代わりに。削除すると正常に動作します。

関連する問題