【发布时间】:2013-12-24 10:09:46
【问题描述】:
我想在我的 hadoop 2.2.0 程序中解析 PDF 文件,我找到了this,按照它所说的,直到现在,我有这三个类:
-
PDFWordCount: 包含 map 和 reduce 函数的主类。 (就像native hadoop wordcount 示例,但我使用了PDFInputFormat类而不是TextInputFormat。 -
PDFRecordReader extends RecordReader<LongWritable, Text>:这是这里的主要工作。特别是我把我的initialize函数放在这里以获得更多说明。public void initialize(InputSplit genericSplit, TaskAttemptContext context) throws IOException, InterruptedException { System.out.println("initialize"); System.out.println(genericSplit.toString()); FileSplit split = (FileSplit) genericSplit; System.out.println("filesplit convertion has been done"); final Path file = split.getPath(); Configuration conf = context.getConfiguration(); conf.getInt("mapred.linerecordreader.maxlength", Integer.MAX_VALUE); FileSystem fs = file.getFileSystem(conf); System.out.println("fs has been opened"); start = split.getStart(); end = start + split.getLength(); System.out.println("going to open split"); FSDataInputStream filein = fs.open(split.getPath()); System.out.println("going to load pdf"); PDDocument pd = PDDocument.load(filein); System.out.println("pdf has been loaded"); PDFTextStripper stripper = new PDFTextStripper(); in = new LineReader(new ByteArrayInputStream(stripper.getText(pd).getBytes( "UTF-8"))); start = 0; this.pos = start; System.out.println("init has finished"); }(您可以查看我的
system.out.printlns 进行调试。 此方法无法将genericSplit转换为FileSplit。我在控制台中看到的最后一件事是:hdfs://localhost:9000/in:0+9396432这是
genericSplit.toString() PDFInputFormat extends FileInputFormat<LongWritable, Text>: 只是在createRecordReader方法中创建new PDFRecordReader。
我想知道我的错误是什么?
我需要额外的课程吗?
【问题讨论】:
-
你没有一些日志吗?请添加 Stacktrace。
-
不,没有
Exception。它只是在那里终止。 -
这不太可能,甚至在您的任务日志中也没有?;-)
-
好的,要么尝试添加像
System.out.println(genericSplit.getClass())这样的打印语句,要么挂在调试器中。您是否将作业提交到正在运行的集群?如果是,那么一定有一些日志。 -
我不知道有什么方法可以调试 map reduce 程序。如果您知道,请通过this question 帮助我。我在 localhost 上有一个 hadoop 单节点设置,并在其上运行测试。
标签: java pdf hadoop hadoop-yarn