Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Adding validity support for StructArray in io::json::read
Browse files Browse the repository at this point in the history
  • Loading branch information
cjermain committed May 12, 2022
1 parent 56ea124 commit 7f00de1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/io/json/read/deserialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,21 @@ fn deserialize_struct<A: Borrow<Value>>(rows: &[A], data_type: DataType) -> Stru
.map(|f| (&f.name, (f.data_type(), vec![])))
.collect::<HashMap<_, _>>();

let mut validity = MutableBitmap::with_capacity(rows.len());

rows.iter().for_each(|row| {
match row.borrow() {
Value::Object(value) => {
values
.iter_mut()
.for_each(|(s, (_, inner))| inner.push(value.get(*s).unwrap_or(&Value::Null)));
validity.push(true);
}
_ => {
values
.iter_mut()
.for_each(|(_, (_, inner))| inner.push(&Value::Null));
validity.push(false);
}
};
});
Expand All @@ -166,7 +170,7 @@ fn deserialize_struct<A: Borrow<Value>>(rows: &[A], data_type: DataType) -> Stru
.map(|(_, (data_type, values))| _deserialize(&values, data_type.clone()))
.collect::<Vec<_>>();

StructArray::new(data_type, values, None)
StructArray::new(data_type, values, validity.into())
}

fn deserialize_dictionary<K: DictionaryKey, A: Borrow<Value>>(
Expand Down

0 comments on commit 7f00de1

Please sign in to comment.