polish(rest api) better error message for ndjson.
@@ -93,12 +93,12 @@ where R: AsyncBufRead + Unpin + Send
.map(|f| f.data_type().create_deserializer(self.builder.block_size))
.collect::<Vec<_>>();
- let names = self
+ let fields = self
.builder
.schema
.fields()
.iter()
- .map(|f| f.name())
+ .map(|f| (f.name(), f.data_type().name()))
.collect::<Vec<_>>();
let mut rows = 0;
@@ -123,11 +123,18 @@ where R: AsyncBufRead + Unpin + Send
}
let json: serde_json::Value = serde_json::from_reader(self.buffer.as_bytes())?;
- // Deserialize each field.
- for (name, deser) in names.iter().zip(packs.iter_mut()) {
+ for ((name, type_name), deser) in fields.iter().zip(packs.iter_mut()) {
let value = &json[name];
- deser.de_json(value)?;
+ deser.de_json(value).map_err(|e| {
+ ErrorCode::BadBytes(format!(
+ "invalid value for column {}: type={}, value={:?}: {}",
+ name,
+ type_name,
+ value,
+ e.message()
+ ))
+ })?;
}
rows += 1;
