gpt4 book ai didi

java - Hadoop 路径添加 %2F

转载 作者:可可西里 更新时间:2023-11-01 17:00:26 25 4
gpt4 key购买 nike

我在 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();


}

最佳答案

问题出在这行代码中

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”替换回“/”即可。

关于java - Hadoop 路径添加 %2F,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24823523/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com