Пользовательская инициализация RecordReader не вызывается
Я недавно начал возиться с Hadoop и просто создал свой собственный формат ввода для обработки PDF.
По какой-то причине мой пользовательский класс RecordReader не имеет вызванного метода инициализации. (проверил это с помощью sysout, потому что я не настроил среду отладки)
Я использую hadoop 2.2.0 на Windows 7 32bit. Делая мои звонки с банкой пряжи, как баночка Hadoop прослушивается под окнами...
import ...
public class PDFInputFormat extends FileInputFormat<Text, Text>
{
@Override
public RecordReader<Text, Text> getRecordReader(InputSplit arg0,
JobConf arg1, Reporter arg2) throws IOException
{
return new PDFRecordReader();
}
public static class PDFRecordReader implements RecordReader<Text, Text>
{
private FSDataInputStream fileIn;
public String fileName=null;
HashSet<String> hset=new HashSet<String>();
private Text key=null;
private Text value=null;
private byte[] output=null;
private int position = 0;
@Override
public Text createValue() {
int endpos = -1;
for (int i = position; i < output.length; i++){
if (output[i] == (byte) '\n') {
endpos = i;
}
}
if (endpos == -1) {
return new Text(Arrays.copyOfRange(output,position,output.length));
}
return new Text(Arrays.copyOfRange(output,position,endpos));
}
@Override
public void initialize(InputSplit genericSplit, TaskAttemptContext job) throws
IOException, InterruptedException
{
System.out.println("initialization is called");
FileSplit split=(FileSplit) genericSplit;
Configuration conf=job.getConfiguration();
Path file=split.getPath();
FileSystem fs=file.getFileSystem(conf);
fileIn= fs.open(split.getPath());
fileName=split.getPath().getName().toString();
System.out.println(fileIn.toString());
PDDocument docum = PDDocument.load(fileIn);
ByteArrayOutputStream boss = new ByteArrayOutputStream();
OutputStreamWriter ow = new OutputStreamWriter(boss);
PDFTextStripper stripper=new PDFTextStripper();
stripper.writeText(docum, ow);
ow.flush();
output = boss.toByteArray();
}
}
}
2 ответа
Как я понял вчера вечером, я мог бы помочь кому-то еще с этим:
RecordReader является устаревшим интерфейсом Hadoop (hadoop.common.mapred) и фактически не содержит метода инициализации, который объясняет, почему он не вызывается автоматически.
Расширение класса RecordReader в hadoop.common.mapreduce позволяет расширить метод инициализации этого класса.
System.out.println()
может не помочь во время работы. Чтобы убедиться, что ваш initialize()
называется или нет попробуй кинь RuntimeException
там, как показано ниже:
@Override
public void initialize(InputSplit genericSplit, TaskAttemptContext job) throws
IOException, InterruptedException
{
throw new NullPointerException("inside initialize()");
....
Это определенно подойдет.