java - hadoop 中多种输入格式作为单一输入格式

标签 java xml hadoop

我面临以下情况。请帮助我。我使用hadoop Mapreduce 来处理XML 文件。

通过引用此网站,我可以滑动我的记录 https://gist.github.com/sritchie/808035 但是当 XML 文件的大小大于 block 大小时,我无法获得正确的值 所以我需要读取整个文件 为此我得到了这个链接

https://github.com/pyongjoo/MapReduce-Example/blob/master/mysrc/XmlInputFormat.java

但现在的问题是如何将两个inputformat实现为单个inputformat

请尽快帮助我 谢谢

更新

public class XmlParser11
{

        public static class XmlInputFormat1 extends TextInputFormat {

        public static final String START_TAG_KEY = "xmlinput.start";
        public static final String END_TAG_KEY = "xmlinput.end";

        @Override
    protected boolean isSplitable(JobContext context, Path file) {
        return false;
        }


        public RecordReader<LongWritable, Text> createRecordReader(InputSplit split, TaskAttemptContext context) {
            return new XmlRecordReader();
        }

        /**
         * XMLRecordReader class to read through a given xml document to output
         * xml blocks as records as specified by the start tag and end tag
         *
         */


        public static class XmlRecordReader extends RecordReader<LongWritable, Text> {
            private byte[] startTag;
            private byte[] endTag;
            private long start;
            private long end;
            private FSDataInputStream fsin;
            private DataOutputBuffer buffer = new DataOutputBuffer();

            private LongWritable key = new LongWritable();
            private Text value = new Text();
            @Override
            public void initialize(InputSplit split, TaskAttemptContext context)
                    throws IOException, InterruptedException {
                Configuration conf = context.getConfiguration();
                startTag = conf.get(START_TAG_KEY).getBytes("utf-8");
                endTag = conf.get(END_TAG_KEY).getBytes("utf-8");
                FileSplit fileSplit = (FileSplit) split;

但不工作

最佳答案

使用isSplitable属性指定不分割文件(即使达到 block 大小)。当您想要确保大文件应由单个映射器处理时,通常使用此方法。

public class XmlInputFormat extends FileInputFormat {
@Override
 protected boolean isSplitable(JobContext context, Path file) {
 return false;
}

@Override
 public RecordReader<LongWritable, Text> createRecordReader(InputSplit split,TaskAttemptContext context)
 throws IOException {
  // return your version of XML record reader
 }
}

或者,您也可以使用以下方法增加每个拆分的 block 大小:

// Set the maximum split size
setMaxSplitSize(MAX_INPUT_SPLIT_SIZE);

关于java - hadoop 中多种输入格式作为单一输入格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20213974/

相关文章:

java - JAXB 解码 xml @XmlValue 和 @XmlElement

python - BeautifulSoup 嵌套标签

java - Spring 从 root 上设置的 urlrewrite 规则中排除页面

java - XML 命名空间如何在没有工作网络连接的情况下工作?

hadoop - hadoop在本地和分布式模式下静态变量的行为是否不同

hadoop - Flume 代理 - 我可以指定像 gzip 或 bz2 这样的压缩吗?

hadoop - 30秒后,我的HMaster消失了。错误

java - 充气城堡 api 出现 asn1 错误

java - Oracle 连接压缩?

java - 有没有办法在不调用 System.exit() 的情况下终止使用 java3d 的 java 应用程序?