Skip to content
Closed
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions arrow-csv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ arrow-data = { version = "33.0.0", path = "../arrow-data" }
arrow-schema = { version = "33.0.0", path = "../arrow-schema" }
chrono = { version = "0.4.23", default-features = false, features = ["clock"] }
csv = { version = "1.1", default-features = false }
csv-async = {version = "1.2.5", features = ["tokio"]}
tokio = { version = "1.0", default-features = false, features = ["macros", "rt", "fs"] }
csv-core = { version = "0.1"}
lazy_static = { version = "1.4", default-features = false }
lexical-core = { version = "^0.8", default-features = false }
regex = { version = "1.7.0", default-features = false, features = ["std", "unicode", "perf"] }

[dev-dependencies]
tempfile = "3.3"
async-tempfile = "0.2.0"
futures = { version = "0.3", default-features = false, features = ["std"] }
24 changes: 21 additions & 3 deletions arrow-csv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@
//! Transfer data between the Arrow memory format and CSV (comma-separated values).

pub mod reader;
pub mod writer;
pub mod writers;

pub use self::reader::infer_schema_from_files;
pub use self::reader::Reader;
pub use self::reader::ReaderBuilder;
pub use self::writer::Writer;
pub use self::writer::WriterBuilder;
pub use self::writers::async_writer::AsyncWriter;
pub use self::writers::async_writer::AsyncWriterBuilder;
pub use self::writers::writer::Writer;
pub use self::writers::writer::WriterBuilder;
use arrow_schema::ArrowError;

fn map_csv_error(error: csv::Error) -> ArrowError {
Expand All @@ -42,3 +44,19 @@ fn map_csv_error(error: csv::Error) -> ArrowError {
_ => ArrowError::CsvError("Error reading CSV file".to_string()),
}
}

fn map_async_csv_error(error: csv_async::Error) -> ArrowError {
match error.kind() {
csv_async::ErrorKind::Io(error) => ArrowError::CsvError(error.to_string()),
csv_async::ErrorKind::Utf8 { pos: _, err } => ArrowError::CsvError(format!(
"Encountered UTF-8 error while reading CSV file: {err}"
)),
csv_async::ErrorKind::UnequalLengths {
expected_len, len, ..
} => ArrowError::CsvError(format!(
"Encountered unequal lengths between records on CSV file. Expected {len} \
records, found {expected_len} records"
)),
_ => ArrowError::CsvError("Error reading CSV file".to_string()),
}
}
Loading