allow null values in csv

This commit is contained in:
ad hoc 2022-02-03 15:46:11 +01:00
parent fda4f229bb
commit bd2262ceea
No known key found for this signature in database
GPG Key ID: 4F00A782990CC643

View File

@ -118,7 +118,10 @@ impl<W: io::Write + io::Seek> DocumentBatchBuilder<W> {
for (value, (fid, ty)) in record.into_iter().zip(headers.iter()) {
let value = match ty {
AllowedType::Number => {
value.parse::<f64>().map(Value::from).map_err(|error| {
if value.trim().is_empty() {
Value::Null
} else {
value.trim().parse::<f64>().map(Value::from).map_err(|error| {
Error::ParseFloat {
error,
// +1 for the header offset.
@ -127,7 +130,14 @@ impl<W: io::Write + io::Seek> DocumentBatchBuilder<W> {
}
})?
}
AllowedType::String => Value::String(value.to_string()),
}
AllowedType::String => {
if value.is_empty() {
Value::Null
} else {
Value::String(value.to_string())
}
}
};
this.value_buffer.clear();