Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Borrow<Value> on infer_json_schema_from_iterator #3728

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions arrow-json/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
//! let batch = json.next().unwrap().unwrap();
//! ```

use std::borrow::Borrow;
use std::io::{BufRead, BufReader, Read, Seek};
use std::sync::Arc;

Expand Down Expand Up @@ -526,16 +527,17 @@ fn collect_field_types_from_object(
/// The reason we diverge here is because we don't have utilities to deal with JSON data once it's
/// interpreted as Strings. We should match Spark's behavior once we added more JSON parsing
/// kernels in the future.
pub fn infer_json_schema_from_iterator<I>(value_iter: I) -> Result<Schema, ArrowError>
pub fn infer_json_schema_from_iterator<I, V>(value_iter: I) -> Result<Schema, ArrowError>
where
I: Iterator<Item = Result<Value, ArrowError>>,
I: Iterator<Item = Result<V, ArrowError>>,
V: Borrow<Value>,
{
let mut field_types: HashMap<String, InferredType> = HashMap::new();

for record in value_iter {
match record? {
match record?.borrow() {
Value::Object(map) => {
collect_field_types_from_object(&mut field_types, &map)?;
collect_field_types_from_object(&mut field_types, map)?;
}
value => {
return Err(ArrowError::JsonError(format!(
Expand Down