【问题标题】:How do I pass Third Argument in hadoop job如何在 hadoop 工作中传递第三个参数
【发布时间】:2014-09-04 14:35:37
【问题描述】:

我正在使用 java 类而不是命令 hadoop jar /input /output 运行我的 hadoop 作业。 在这种情况下,我的命令如下所示。 hadoop jar Main.class /input/location /output/location /thirdargument/file。 我知道如何在 Main 的 Driver 类中添加输入路径和输出路径,但是如何添加输入所依赖的第三个参数以获得输出。 下面是我添加输入和输出路径的方法。

请帮忙添加第三个参数。

FileInputFormat.addInputPath(job, new Path("/path1/"));     //inputpath
FileOutputFormat.setOutputPath(job, new Path("/path2/"));   //outputpath

第三个参数添加?

【问题讨论】:

    标签: hadoop mapreduce hadoop2


    【解决方案1】:

    我不知道是否可以通过添加另一个路径来获取第三个文件,但您可以使用,

    try{
    Path pt=new Path("hdfs://npvm11.np.wc1.yellowpages.com:9000/user/john/abc.txt");
    FileSystem fs = FileSystem.get(new Configuration());
    BufferedReader br=new BufferedReader(new InputStreamReader(fs.open(pt)));
    String line;
    line=br.readLine();
    while (line != null){
    System.out.println(line);
    line=br.readLine();
    }
    }catch(Exception e){
    }
    

    我从:https://sites.google.com/site/hadoopandhive/home/hadoop-how-to-read-a-file-from-hdfs得到它

    【讨论】:

    • 是的。看到这个,不知道怎么加这个。无论如何感谢您的回答。我会尝试实现它。
    【解决方案2】:

    我检查了这个方法。这个对我有用。 (Apache Hadoop 1.2.1)

    FileInputFormat.setInputPaths(conf, new Path(args[0])); // 输入1 FileInputFormat.setInputPaths(conf, new Path(args[1])); // 输入2 FileOutputFormat.setOutputPath(conf, new Path(args[2]));//输出

    我在发出命令时传递这些参数。

    hadoop jar <jarfilepath> <class name> <Input1> <Input2> <Output>

    【讨论】:

    • 您是如何使用该文件的,似乎没有对输入和输出文件的任何引用
    • @AntarikshaYelkawar 我在 java 程序中进行了这些更改。然后从客户端机器的终端传递输入文件的hdfs路径。 @Srinivas - 太好了。不客气:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-19
    • 1970-01-01
    • 2011-05-22
    • 1970-01-01
    • 2015-11-13
    • 2022-07-04
    • 2015-11-12
    相关资源
    最近更新 更多