mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-02-21 18:15:29 +08:00
Merge #445
445: allow null values in csv r=Kerollmops a=MarinPostma This pr allows null values in csv: - if the field is of type string, then an empty field is considered null (`,,`), anything other is turned into a string (i.e `, ,` is a single whitespace string) - if the field is of type number, when the trimmed field is empty, we consider the value null (i.e `,,`, `, ,` are both null numbers) otherwise we try to parse the number. Co-authored-by: ad hoc <postma.marin@protonmail.com>
This commit is contained in:
commit
267d14c28d
@ -118,7 +118,10 @@ impl<W: io::Write + io::Seek> DocumentBatchBuilder<W> {
|
|||||||
for (value, (fid, ty)) in record.into_iter().zip(headers.iter()) {
|
for (value, (fid, ty)) in record.into_iter().zip(headers.iter()) {
|
||||||
let value = match ty {
|
let value = match ty {
|
||||||
AllowedType::Number => {
|
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::ParseFloat {
|
||||||
error,
|
error,
|
||||||
// +1 for the header offset.
|
// +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();
|
this.value_buffer.clear();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user