hadoop(1.1.2)xml处理与重写文件

t1rydlwq  于 2021-06-03  发布在  Hadoop
关注(0)|答案(1)|浏览(330)

第一个问题。。。学习hadoop。。。
我花了两个星期的时间试图理解hadoop的一切,但似乎每座山后面都有一座山。
设置如下:
大量(100万)小的(<50mb)xml文件(格式化为xml的文档)。
每个文件都是一个记录
伪分布式hadoop集群(1.1.2)
使用旧的mapred api(如果新api支持所需的内容,则可以更改)
我发现xmlinputformat(“mahoutxmlinputformat”)是读取文件的良好起点,因为我可以将整个xml文档指定为
我的理解是xmlinputformat将负责确保每个文件都是它自己的记录(因为每个文件/记录都有一个标记)。
我的问题是:我想使用hadoop处理每个文档,搜索信息,然后,为每个文件/记录重新编写或输出一个添加了新xml标记的新xml文档。
不害怕阅读和学习,但是一个可以玩的 backbone 真的可以帮助我“玩”和学习hadoop
这是我的司机:

public static void main(String[] args) {
    JobConf conf = new JobConf(myDriver.class);
    conf.setJobName("bigjob");
    // Input/Output Directories
    if (args[0].length()==0 || args[1].length()==0) System.exit(-1);
    FileInputFormat.setInputPaths(conf, new Path(args[0]));
    FileOutputFormat.setOutputPath(conf, new Path(args[1]));

    conf.set("xmlinput.start", "<document>");
    conf.set("xmlinput.end", "</document>");

    // Mapper & Combiner & Reducer
    conf.setMapperClass(Mapper.class);
    conf.setReducerClass(Reduce.class);
    conf.setNumReduceTasks(0);

    // Input/Output Types
    conf.setInputFormat(XmlInputFormat.class);

    conf.setOutputFormat(?????);

    conf.setOutputKeyClass(????);
    conf.setOutputValueClass(????);

    try {
            JobClient.runJob(conf);
    } catch (Exception e) {
            e.printStackTrace();
    }
}
b0zn9rqh

b0zn9rqh1#

我想说一个简单的解决办法就是 TextOutputFormat 然后使用 Text 作为输出键 NullWritable 作为输出值。 TextOutputFormat 使用分隔字符分隔从作业输出的键和值对。对于您的需求,您不需要这种安排,但是您只想输出一个xml体。如果传递null或nullwritable作为输出键或值, TextOutputFormat 不会写入null或分隔符,只写入非null键或值。
使用xmlinputformat的另一种方法是使用wholefileinput(如tom white的hadoop-the-definal guide中所述)。
因此,您需要编写Map器来使用输入值文本对象(可能使用xmlsax或dom解析器),然后将转换后的xml作为文本对象输出。

相关问题