From bd2262ceeaf3fa9b87724d8ae56d69f426504ed6 Mon Sep 17 00:00:00 2001 From: ad hoc Date: Thu, 3 Feb 2022 15:46:11 +0100 Subject: [PATCH] allow null values in csv --- milli/src/documents/builder.rs | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/milli/src/documents/builder.rs b/milli/src/documents/builder.rs index f95fa9190..2860c4b86 100644 --- a/milli/src/documents/builder.rs +++ b/milli/src/documents/builder.rs @@ -118,16 +118,26 @@ impl DocumentBatchBuilder { for (value, (fid, ty)) in record.into_iter().zip(headers.iter()) { let value = match ty { AllowedType::Number => { - value.parse::().map(Value::from).map_err(|error| { - Error::ParseFloat { - error, - // +1 for the header offset. - line: i + 1, - value: value.to_string(), - } - })? + if value.trim().is_empty() { + Value::Null + } else { + value.trim().parse::().map(Value::from).map_err(|error| { + Error::ParseFloat { + error, + // +1 for the header offset. + line: i + 1, + value: value.to_string(), + } + })? + } + } + AllowedType::String => { + if value.is_empty() { + Value::Null + } else { + Value::String(value.to_string()) + } } - AllowedType::String => Value::String(value.to_string()), }; this.value_buffer.clear();