【问题标题】:Hadoop path adding %2FHadoop 路径添加 %2F
【发布时间】:2014-07-18 21:00:02
【问题描述】:

我在 hadoop 中有一个文件:/home/hduser/IH/input/imageslocalpaths.txt(我已经使用 hadoop fs -ls IH/input/imageslocalpaths.txt 检查了它是否存在)。 当我跑步时:

hadoop jar IH.jar IH/input/imageslocalpaths.txt

我明白了:

Input path does not exist: hdfs://localhost:54310/user/hduser/IH%2Finput%2Fimageslocalpaths.txt

谁能告诉我如何阻止 Hadoop 将斜杠更改为 %2F 或其他解决方法?

(我已经尝试了完整路径,但 hadoop 只是将它添加到 /user/hduser 的末尾,给 /user/hduser/user/hduser... 仍然使用 %2F)。

这里请求的是我的主要内容(你想要其他位吗?)

    public static void main(String[] args) throws Exception {

        Configuration conf = new Configuration();
        Configuration conf2 = new Configuration();

        conf.set("fs.defaultFS", "hdfs://localhost:54310");

        String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();

        Job job1 = new Job(conf, "MergeImages");

        job1.setJarByClass(ImageHandlerMain.class);
        job1.setMapperClass(BinaryFilesToHadoopSequenceFileMapper.class);
        job1.setOutputKeyClass(Text.class);
        job1.setOutputValueClass(BytesWritable.class);

        FileInputFormat.addInputPath(job1, new Path(URLEncoder.encode(otherArgs[0],"UTF-8")));
        job1.setInputFormatClass(TextInputFormat.class);     

        FileOutputFormat.setOutputPath(job1, new Path(URLEncoder.encode(otherArgs[1],"UTF-8"))); //put result into intermediate folder
        job1.setInputFormatClass(TextInputFormat.class);
        job1.setOutputFormatClass(SequenceFileOutputFormat.class);
        ControlledJob cJob1 = new ControlledJob(conf);
        cJob1.setJob(job1);

        Job job2 = new Job(conf2,"FindDuplicates");

        job2.setJarByClass(ImageHandlerMain.class);
        job2.setMapperClass(ImagePHashMapper.class); 
        job2.setReducerClass(ImageDupsReducer.class);
        job2.setOutputKeyClass(Text.class);
        job2.setOutputValueClass(Text.class);        
        FileInputFormat.addInputPath(job2, new Path(URLEncoder.encode(otherArgs[1],"UTF-8") + "/part-r-00000")); //get the part-r-00000 file from the intermediate folder
        FileOutputFormat.setOutputPath(job2, new  Path(otherArgs[2])); //put result into output folder
        job2.setInputFormatClass(SequenceFileInputFormat.class);
        ControlledJob cJob2 = new ControlledJob(conf2);
        cJob2.setJob(job2);
        JobControl jobctrl = new JobControl("jobctrl");
        jobctrl.addJob(cJob1);
        jobctrl.addJob(cJob2);
        cJob2.addDependingJob(cJob1);
        jobctrl.run();


}

【问题讨论】:

  • 请分享生成jar文件的java代码?

标签: java linux hadoop


【解决方案1】:

问题出在这行代码

FileInputFormat.addInputPath(job2, new Path(URLEncoder.encode(otherArgs[1],"UTF-8") + "/part-r-00000")); //get the part-r-00000 file from the intermediate folder

当您使用 URLEncoder.encode 创建路径时,它会将“/”转换为 %2F。

可能的解决方法

FileInputFormat.addInputPath(job2, new Path(URLEncoder.encode(otherArgs[1],"UTF-8").replace("%2F", "/") + "/part-r-00000")); //get the part-r-00000 file from the intermediate folder

编码后只需用替换方法将“%2F”替换回“/”。

【讨论】:

    【解决方案2】:

    我不确定问题可能来自哪里,但请尝试检查以下内容:

    • 解析中的参数后检查url格式是否正确

    String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();

    • 尝试在不使用 URL 编码器的情况下创建路径,如下所示:

    FileInputFormat.setInputPaths(job, new Path(inputLocation)); //其中 inputLocation 只是一个字符串

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-13
      • 2021-03-22
      • 1970-01-01
      • 2018-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多