Appending to existing sequence file is overwriting the content

520 views Asked by At

I am using below code snippet for sequence file writer but it works fine if sequence file doesn't exist but it does then it overwrites the content rather than appending to it.

SequenceFile.Writer writer = SequenceFile.createWriter(FileContext.getFileContext(conf), conf, sequenceFile, Text.class, Text.class, CompressionType.NONE, null, new Metadata(), EnumSet.of(CreateFlag.CREATE, CreateFlag.APPEND));

Please note: I am using hadoop 2.7.2.

Can anyone please help on how do I append to an existing sequence file?

Also I tried below option as well but no luck:

Writer writer = SequenceFile.createWriter(conf, SequenceFile.Writer.file(sequenceFile), SequenceFile.Writer.keyClass(Text.class), SequenceFile.Writer.valueClass(Text.class), SequenceFile.Writer.appendIfExists(true), metadataOption);

Thanks in Advance!

1

There are 1 answers

3
Tahir Hussain Mir On

Use Writer in case of SequenceFile.Writer like this:

Writer writer = SequenceFile.createWriter(//required params);

And then use the its append method.

Writer.append(param1, param2);

I hope this link may help You.

Here is the link Allow appending to existing SequenceFiles. The issue has been solved in 2.7.2