Я пытаюсь решить следующую проблему RecordReader. Пример входной файл:Hadoop Map-Reduce. RecordReader
1,1
2,2
3,3
4,4
5,5
6,6
7,7
.......
.......
я хочу, чтобы мой RecordReader вернуть
key | Value
0 |1,1:2,2:3,3:4,4:5,5
4 |2,2:3,3:......6,6
6 |3,3:4,4......6,6,7,7
(для первого значения первых пяти линий, для второго значений пяти линий, начиная с 2-ем линии и по 3-й величине пяти линий, начиная с третья линия и т.д.)
public class MyRecordReader extends RecordReader<LongWritable, Text> {
@Override
public boolean nextKeyValue() throws IOException, InterruptedException {
while (pos < end) {
key.set(pos);
// five line logic
Text nextLine=new Text();
int newSize = in.readLine(value, maxLineLength,
Math.max((int)Math.min(Integer.MAX_VALUE, end-pos),
maxLineLength));
fileSeek+=newSize;
for(int n=0;n<4;n++)
{
fileSeek+=in.readLine(nextLine, maxLineLength,
Math.max((int)Math.min(Integer.MAX_VALUE, end-pos),
maxLineLength));
value.append(":".getBytes(), 0,1);
value.append(nextLine.getBytes(), 0, nextLine.getLength());
}
if (newSize == 0) {
return false;
}
pos += newSize;
if (newSize < maxLineLength) {
return true;
}
// line too long. try again
LOG.info("Skipped line of size " + newSize + " at pos " + (pos - newSize));
}
return false;
}
}
Но это возвращение значения, как
key | Value
0 |1,1:2,2:3,3:4,4:5,5
4 |6,6:7,7.......10,10
6 |11,11:12,12:......14,14
может кто-то помочь мне с этим кодом или свежий код для RecodeReader будет делать, а? Requirement of the problem (may help you understand the use case) Благодаря
отформатируйте вопрос правильно и правильно показать выход, тогда мы сможем ответить ... – codeling
@nyarlathotep: sry для плохого формата. il попытаться улучшить его, все еще мог hv помог мне справиться с ans. –