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

Improve API for csv::infer_file_schema by removing redundant ref #1776

Merged
merged 2 commits into from
Jun 2, 2022
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
13 changes: 7 additions & 6 deletions arrow/src/csv/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub struct ReaderOptions {
/// Return inferred schema and number of records used for inference. This function does not change
/// reader cursor offset.
pub fn infer_file_schema<R: Read + Seek>(
reader: &mut R,
reader: R,
delimiter: u8,
max_read_records: Option<usize>,
has_header: bool,
Expand All @@ -136,12 +136,13 @@ pub fn infer_file_schema<R: Read + Seek>(
}

fn infer_file_schema_with_csv_options<R: Read + Seek>(
reader: &mut R,
roptoins: ReaderOptions,
mut reader: R,
roptions: ReaderOptions,
) -> Result<(Schema, usize)> {
let saved_offset = reader.seek(SeekFrom::Current(0))?;

let (schema, records_count) = infer_reader_schema_with_csv_options(reader, roptoins)?;
let (schema, records_count) =
infer_reader_schema_with_csv_options(&mut reader, roptions)?;
// return the reader seek back to the start
reader.seek(SeekFrom::Start(saved_offset))?;

Expand All @@ -155,7 +156,7 @@ fn infer_file_schema_with_csv_options<R: Read + Seek>(
///
/// Return infered schema and number of records used for inference.
pub fn infer_reader_schema<R: Read>(
reader: &mut R,
reader: R,
delimiter: u8,
max_read_records: Option<usize>,
has_header: bool,
Expand All @@ -170,7 +171,7 @@ pub fn infer_reader_schema<R: Read>(
}

fn infer_reader_schema_with_csv_options<R: Read>(
reader: &mut R,
reader: R,
roptions: ReaderOptions,
) -> Result<(Schema, usize)> {
let mut csv_reader = Reader::build_csv_reader(
Expand Down