1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use json_deserializer::parse;
use crate::array::Array;
use crate::datatypes::DataType;
use crate::error::Error;
use super::super::super::json::read::_deserialize;
pub fn deserialize(rows: &[String], data_type: DataType) -> Result<Box<dyn Array>, Error> {
if rows.is_empty() {
return Err(Error::ExternalFormat(
"Cannot deserialize 0 NDJSON rows because empty string is not a valid JSON value"
.to_string(),
));
}
deserialize_iter(rows.iter().map(|x| x.as_ref()), data_type)
}
pub fn deserialize_iter<'a>(
rows: impl Iterator<Item = &'a str>,
data_type: DataType,
) -> Result<Box<dyn Array>, Error> {
let rows = rows
.map(|row| parse(row.as_bytes()).map_err(Error::from))
.collect::<Result<Vec<_>, Error>>()?;
Ok(_deserialize(&rows, data_type))
}