2016-10-02 9 views
0

Hadoopを初めて使用しています。私は以下のコードを使用してHDFS上の既存のファイルを読み込もうとしています。構成はファイルと思われ、ファイルのパスも正しいです。 - 私は、コードを実行したときにHadoopマップReduce - HDFSファイルを読み込む - FileAlreadyExistsエラー

public static class Map extends Mapper<LongWritable, Text, Text, Text> { 

    private static Text f1, f2, hdfsfilepath; 
    private static HashMap<String, ArrayList<String>> friendsData = new HashMap<>(); 

    public void setup(Context context) throws IOException { 
     Configuration conf = context.getConfiguration(); 
     Path path = new Path("hdfs://cshadoop1" + conf.get("hdfsfilepath")); 
     FileSystem fs = FileSystem.get(path.toUri(), conf); 
     if (fs.exists(path)) { 
     BufferedReader br = new BufferedReader(
      new InputStreamReader(fs.open(path))); 
     String line; 
     line = br.readLine(); 
     while (line != null) { 
      StringTokenizer str = new StringTokenizer(line, ","); 
      String friend = str.nextToken(); 
      ArrayList<String> friendDetails = new ArrayList<>(); 
      while (str.hasMoreTokens()) { 
      friendDetails.add(str.nextToken()); 
      } 
      friendsData.put(friend, friendDetails); 
     } 
     } 
    } 

    public void map(LongWritable key, Text value, Context context) 
     throws IOException, InterruptedException { 
     for (String k : friendsData.keySet()) { 
     context.write(new Text(k), new Text(friendsData.get(k).toString())); 
     } 
    } 
    } 

私は以下の例外を取得しています -

Exception in thread "main" org.apache.hadoop.mapred.FileAlreadyExistsException: Output directory hdfs://cshadoop1/socNetData/userdata/userdata.txt already exists 
     at org.apache.hadoop.mapreduce.lib.output.FileOutputFormat.checkOutputSpecs(FileOutputFormat.java:146) 
     at org.apache.hadoop.mapreduce.JobSubmitter.checkSpecs(JobSubmitter.java:458) 
     at org.apache.hadoop.mapreduce.JobSubmitter.submitJobInternal(JobSubmitter.java:343) 

私は既存のファイルを読み込むしようとしています。私がここで紛失しているものは何ですか?助けをお待ちしています。

答えて

2

例外は、あなたの出力ディレクトリが既に存在しているが、それはいけないことを示しています。それを削除するか、名前を変更します。

また、出力ディレクトリ 'userdata.txt'の名前は、ファイルの名前のようになります。だからあなたの入力/出力ディレクトリで間違っていないことを確認してください。

関連する問題