2017-04-27 13 views
0

サンプルデータinput.txtの下には、2列のキー&の値があります。マッパーによって処理された各レコードに対して、マップの出力はMapperから複数の出力を書き込む

1)に書き込まれるべきHDFS =>新しいファイルがキー列

2)コンテキストオブジェクトの下

に基づいて作成する必要があるコードでありますキー列に基づいて4つのファイルを作成する必要がありますが、ファイルは作成されません。出力も正しくありません。私はワードカウントの出力を期待していますが、文字カウント出力を取得しています。

input.txt 
------------ 
key   value 
HelloWorld1|ID1 
HelloWorld2|ID2 
HelloWorld3|ID3 
HelloWorld4|ID4 



    public static class MapForWordCount extends Mapper<LongWritable, Text, Text, IntWritable> { 
     public void map(LongWritable key, Text value, Context con) throws IOException, InterruptedException { 

      String line = value.toString(); 
      String[] fileContent = line.split("|"); 
      Path hdfsPath = new Path("/filelocation/" + fileContent[0]); 
      System.out.println("FilePath : " +hdfsPath); 

      Configuration configuration = con.getConfiguration(); 
      writeFile(fileContent[1], hdfsPath, configuration); 

      for (String word : fileContent) { 
       Text outputKey = new Text(word.toUpperCase().trim()); 
       IntWritable outputValue = new IntWritable(1); 
       con.write(outputKey, outputValue); 
      }  
     } 

     static void writeFile(String fileContent, Path hdfsPath, Configuration configuration) throws IOException { 

      FileSystem fs = FileSystem.get(configuration); 
       FSDataOutputStream fin = fs.create(hdfsPath); 
       fin.writeUTF(fileContent); 
       fin.close(); 
     } 
    } 

答えて