Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CsvExternalSort.sortInBatch drops a row for each batch #29

Closed
z9security opened this issue Apr 21, 2020 · 4 comments
Closed

CsvExternalSort.sortInBatch drops a row for each batch #29

z9security opened this issue Apr 21, 2020 · 4 comments

Comments

@z9security
Copy link

In the case where if (currentBlock.get() < blocksize) is false, the CSVRecord e is lost. You'll notice this as a missing row for each block.

My solution was to remove the conditional logic for processing e, and add the conditional logic only in the part where the block is processed.

Here is my updated code:
` try (CSVParser parser = new CSVParser(fbr, sortOptions.getFormat())) {
parser.spliterator().forEachRemaining(e -> {
if (e.getRecordNumber() <= sortOptions.getNumHeader()) {
header[0] = e;
} else {
tmplist.add(e);
currentBlock.addAndGet(SizeEstimator.estimatedSizeOf(e));
}
if (currentBlock.get() >= blocksize) {
try {
files.add(sortAndSave(tmplist, tmpdirectory, sortOptions, header[0]));
} catch (IOException e1) {
logger.warn(String.format("Error during the sort in batch"),e1); //$NON-NLS-1$
}
tmplist.clear();
currentBlock.getAndSet(0);
}

		});
	}

`

@z9security
Copy link
Author

CsvExternalSort.java.txt

@lemire
Copy link
Owner

lemire commented Apr 21, 2020

I agree that it is a bug and I agree that your fix is correct. Will merge manually and issue a release.

@lemire
Copy link
Owner

lemire commented Apr 21, 2020

Closing.

@lemire lemire closed this as completed Apr 21, 2020
@z9security
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants