私のhadoop 2.2.0プログラムでPDFファイルを解析したいのですが、これを見つけて、それが言うことに従いました。今まで、次の3つのクラスがあります。
PDFWordCount
: map 関数と reduce 関数を含むメイン クラス。(ネイティブの Hadoop ワードカウントサンプルと同様ですが、代わりにクラスTextInputFormat
を使用しました。PDFInputFormat
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.println
(デバッグ用に s を見ることができます。このメソッドは への変換genericSplit
に失敗しますFileSplit
。コンソールに最後に表示されるのは、次のとおりです。hdfs://localhost:9000/in:0+9396432
これは
genericSplit.toString()
PDFInputFormat extends FileInputFormat<LongWritable, Text>
:メソッドで作成するだけnew PDFRecordReader
です。createRecordReader
私の間違いを知りたいですか?
追加のクラスか何かが必要ですか?