This is an automated email from the ASF dual-hosted git repository.
nevime pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new c4a65b4 ARROW-10876 [Rust] validate row value type in json reader
c4a65b4 is described below
commit c4a65b42c59f860262f81bc38c09794f938f1312
Author: Qingping Hou <[email protected]>
AuthorDate: Sat Dec 12 23:43:58 2020 +0200
ARROW-10876 [Rust] validate row value type in json reader
Closes #8895 from houqp/qp_validate_json
Authored-by: Qingping Hou <[email protected]>
Signed-off-by: Neville Dipale <[email protected]>
---
rust/arrow/src/json/reader.rs | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/rust/arrow/src/json/reader.rs b/rust/arrow/src/json/reader.rs
index 873baf8..5561c42 100644
--- a/rust/arrow/src/json/reader.rs
+++ b/rust/arrow/src/json/reader.rs
@@ -550,7 +550,16 @@ impl Decoder {
let mut rows: Vec<Value> = Vec::with_capacity(self.batch_size);
for value in value_iter.by_ref().take(self.batch_size) {
- rows.push(value?);
+ let v = value?;
+ match v {
+ Value::Object(_) => rows.push(v),
+ _ => {
+ return Err(ArrowError::JsonError(format!(
+ "Row needs to be of type object, got: {:?}",
+ v
+ )));
+ }
+ }
}
if rows.is_empty() {
// reached end of file
@@ -1970,6 +1979,19 @@ mod tests {
}
#[test]
+ fn test_row_type_validation() {
+ let builder =
ReaderBuilder::new().infer_schema(None).with_batch_size(64);
+ let json_content = "
+ [1, \"hello\"]
+ \"world\"";
+ let re = builder.build(Cursor::new(json_content));
+ assert_eq!(
+ re.err().unwrap().to_string(),
+ r#"Json error: Expected JSON record to be an object, found
Array([Number(1), String("hello")])"#,
+ );
+ }
+
+ #[test]
fn test_list_of_string_dictionary_from_json() {
let schema = Schema::new(vec![Field::new(
"events",