Skip to content

Commit

Permalink
Fix bug where header wasn't sent to additional chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Sully committed Nov 14, 2018
1 parent a610ec5 commit 9b0d25a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/split/splitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,22 @@ impl Splitter {
let mut chunk_id = writer.chunk_id;
let mut rows_sent_to_chunk = 0;
let mut file = writer.output(chunk_id).expect("Could not open file");
let mut header: Option<String> = None;
for row in writer.receiver.iter() {
if header.is_none() {
header = Some(row.clone());
}
if let Some(chunk_size) = writer.chunk_size {
if rows_sent_to_chunk > chunk_size {
if rows_sent_to_chunk > (chunk_size + 1) { // add one for header
// This should only ever happen if we weren't
// able to pre-calculate how many chunks were
// needed
chunk_id = chunk_id.map(|c| c + 2);
file = writer.output(chunk_id).expect("Could not open file");
rows_sent_to_chunk = 0;
writer
.handle_row(&mut file, header.as_ref().unwrap())
.expect("Could not write row to file");
rows_sent_to_chunk = 1;
}
}
writer
Expand Down
2 changes: 1 addition & 1 deletion src/split/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl SplitWriter {
self.next_index += 1;
}
None => {
// Start again at the first next chunk
// Start again at the next chunk
self.chunk_senders[0].send(row)?;
self.next_index = 1;
}
Expand Down

0 comments on commit 9b0d25a

Please sign in to comment.