1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use std::num::NonZeroUsize;

use arrow::array::StructArray;
use polars_core::prelude::*;

pub(crate) mod buffer;
pub mod core;

pub fn infer_schema<R: std::io::BufRead>(
    reader: &mut R,
    infer_schema_len: Option<NonZeroUsize>,
) -> PolarsResult<Schema> {
    let data_types = polars_json::ndjson::iter_unique_dtypes(reader, infer_schema_len)?;
    let data_type =
        crate::json::infer::data_types_to_supertype(data_types.map(|dt| DataType::from(&dt)))?;
    let schema = StructArray::get_fields(&data_type.to_arrow(true))
        .iter()
        .collect();
    Ok(schema)
}