簡體   English   中英

Hadoop Map Reduce-讀取HDFS文件-FileAlreadyExists錯誤

[英]Hadoop Map Reduce - Read HDFS File - FileAlreadyExists error

我是Hadoop的新手。 我正在嘗試使用以下代碼讀取HDFS上的現有文件。 配置似乎文件,並且文件路徑也正確。 --

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)

我只是想讀取一個現有文件。 有什么想法我在這里想念的嗎? 感謝任何幫助。

異常告訴您輸出目錄已經存在,但不應該存在。 刪除或更改其名稱。

此外,輸出目錄“ userdata.txt”的名稱看起來像文件名。 因此,請檢查您在輸入/輸出目錄中沒有記錯。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM