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

Use BufRead for JSON Schema Inference #4041

Merged
merged 1 commit into from
Apr 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions arrow-json/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,17 @@ fn generate_schema(spec: HashMap<String, InferredType>) -> Result<Schema, ArrowE
/// }
/// ```
#[derive(Debug)]
pub struct ValueIter<'a, R: Read> {
reader: &'a mut BufReader<R>,
pub struct ValueIter<'a, R: BufRead> {
reader: &'a mut R,
max_read_records: Option<usize>,
record_count: usize,
// reuse line buffer to avoid allocation on each record
line_buf: String,
}

impl<'a, R: Read> ValueIter<'a, R> {
impl<'a, R: BufRead> ValueIter<'a, R> {
/// Creates a new `ValueIter`
pub fn new(reader: &'a mut BufReader<R>, max_read_records: Option<usize>) -> Self {
pub fn new(reader: &'a mut R, max_read_records: Option<usize>) -> Self {
Self {
reader,
max_read_records,
Expand All @@ -207,7 +207,7 @@ impl<'a, R: Read> ValueIter<'a, R> {
}
}

impl<'a, R: Read> Iterator for ValueIter<'a, R> {
impl<'a, R: BufRead> Iterator for ValueIter<'a, R> {
type Item = Result<Value, ArrowError>;

fn next(&mut self) -> Option<Self::Item> {
Expand Down Expand Up @@ -303,8 +303,8 @@ pub fn infer_json_schema_from_seekable<R: Read + Seek>(
/// // seek back to start so that the original file is usable again
/// file.seek(SeekFrom::Start(0)).unwrap();
/// ```
pub fn infer_json_schema<R: Read>(
reader: &mut BufReader<R>,
pub fn infer_json_schema<R: BufRead>(
reader: &mut R,
max_read_records: Option<usize>,
) -> Result<Schema, ArrowError> {
infer_json_schema_from_iterator(ValueIter::new(reader, max_read_records))
Expand Down