Support CSV again

This commit is contained in:
Clément Renault
2024-09-10 21:10:28 +01:00
parent c1c44a0b81
commit 8287c2644f
4 changed files with 147 additions and 48 deletions

View File

@ -423,7 +423,7 @@ async fn document_addition(
}
};
let (uuid, update_file) = index_scheduler.create_update_file(dry_run)?;
let (uuid, mut update_file) = index_scheduler.create_update_file(dry_run)?;
let temp_file = match tempfile() {
Ok(file) => file,
@ -459,20 +459,14 @@ async fn document_addition(
return Err(MeilisearchHttpError::Payload(ReceivePayload(Box::new(e))));
}
let read_file = BufReader::new(buffer.into_inner().into_std().await);
let read_file = buffer.into_inner().into_std().await;
let documents_count = tokio::task::spawn_blocking(move || {
let mut update_file = std::io::BufWriter::new(update_file);
let documents_count = match format {
PayloadType::Json => read_json(read_file, &mut update_file)?,
PayloadType::Csv { delimiter } => read_csv(read_file, &mut update_file, delimiter)?,
PayloadType::Ndjson => read_ndjson(read_file, &mut update_file)?,
PayloadType::Json => read_json(&read_file, &mut update_file)?,
PayloadType::Csv { delimiter } => read_csv(&read_file, &mut update_file, delimiter)?,
PayloadType::Ndjson => read_ndjson(&read_file, &mut update_file)?,
};
// we NEED to persist the file here because we moved the `udpate_file` in another task.
// TODO better support of errors
let update_file = match update_file.into_inner() {
Ok(update_file) => update_file,
Err(_) => todo!("handle errors"),
};
update_file.persist()?;
Ok(documents_count)
})