2010YOUY01 opened a new pull request, #6062: URL: https://github.com/apache/arrow-rs/pull/6062
# Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> Part of https://github.com/apache/arrow-rs/issues/5374 (Actual code change in this PR is < 10 lines) # Rationale for this change Let arrow-csv able to read csv file and generate `StringViewArray` as output. Here is a quick benchmark, and the result looks reasonable. Benchmark is reading 3 string columns in TPCH-lineitem table (char(10), char(25), varchar(44)), parsing them all to `StringViewArray`/`StringArray` and do nothing, the result is: ``` Time to read String columns(char(10), char(25), varchar(44)) from lineitem.csv: 2.493634399s Time to read StringView columns(char(10), char(25), varchar(44)) from lineitem.csv: 2.618616989s ``` <details><summary>Benchmark Code</summary> <p> ```rust extern crate arrow; extern crate criterion; use std::fs::File; use std::sync::Arc; use std::time::Instant; use arrow::csv::ReaderBuilder; use arrow::datatypes::*; fn read_string() { let file = File::open("/Users/yongting/Desktop/code/my_datafusion/arrow-datafusion/benchmarks/data/tpch_sf1/lineitem.tbl").unwrap(); let schema = Arc::new(Schema::new(vec![ Field::new("l_orderkey", DataType::Int64, false), Field::new("l_partkey", DataType::Int64, false), Field::new("l_suppkey", DataType::Int64, false), Field::new("l_linenumber", DataType::Int32, false), Field::new("l_quantity", DataType::Decimal128(15, 2), false), Field::new("l_extendedprice", DataType::Decimal128(15, 2), false), Field::new("l_discount", DataType::Decimal128(15, 2), false), Field::new("l_tax", DataType::Decimal128(15, 2), false), Field::new("l_returnflag", DataType::Utf8, false), Field::new("l_linestatus", DataType::Utf8, false), Field::new("l_shipdate", DataType::Date32, false), Field::new("l_commitdate", DataType::Date32, false), Field::new("l_receiptdate", DataType::Date32, false), Field::new("l_shipinstruct", DataType::Utf8, false), Field::new("l_shipmode", DataType::Utf8, false), Field::new("l_comment", DataType::Utf8, false), Field::new("placeholder", DataType::Int64, true), ])); let csv_reader_string = ReaderBuilder::new(schema.clone()) .with_delimiter(b'|') .with_projection(vec![13, 14, 15]) .build(file) .unwrap(); csv_reader_string.collect::<Result<Vec<_>, _>>().unwrap(); } fn read_stringview() { let file = File::open("/Users/yongting/Desktop/code/my_datafusion/arrow-datafusion/benchmarks/data/tpch_sf1/lineitem.tbl").unwrap(); let schema = Arc::new(Schema::new(vec![ Field::new("l_orderkey", DataType::Int64, false), Field::new("l_partkey", DataType::Int64, false), Field::new("l_suppkey", DataType::Int64, false), Field::new("l_linenumber", DataType::Int32, false), Field::new("l_quantity", DataType::Decimal128(15, 2), false), Field::new("l_extendedprice", DataType::Decimal128(15, 2), false), Field::new("l_discount", DataType::Decimal128(15, 2), false), Field::new("l_tax", DataType::Decimal128(15, 2), false), Field::new("l_returnflag", DataType::Utf8, false), Field::new("l_linestatus", DataType::Utf8, false), Field::new("l_shipdate", DataType::Date32, false), Field::new("l_commitdate", DataType::Date32, false), Field::new("l_receiptdate", DataType::Date32, false), Field::new("l_shipinstruct", DataType::Utf8View, false), Field::new("l_shipmode", DataType::Utf8View, false), Field::new("l_comment", DataType::Utf8View, false), Field::new("placeholder", DataType::Int64, true), ])); let csv_reader_string = ReaderBuilder::new(schema.clone()) .with_delimiter(b'|') .with_projection(vec![13, 14, 15]) .build(file) .unwrap(); csv_reader_string.collect::<Result<Vec<_>, _>>().unwrap(); } fn main() { let n_warmcache_run = 2; let n_run = 3; for _ in 1..=n_warmcache_run { read_string(); } let start_time1 = Instant::now(); for _ in 1..=n_run { read_string(); } let duration1 = start_time1.elapsed(); for _ in 1..=n_warmcache_run { read_stringview(); } let start_time2 = Instant::now(); for _ in 1..=n_run { read_stringview(); } let duration2 = start_time2.elapsed(); println!( "Time to read String columns(char(10), char(25), varchar(44)) from lineitem.csv: {:?}", duration1 / n_run ); println!( "Time to read StringView columns(char(10), char(25), varchar(44)) from lineitem.csv: {:?}", duration2 / n_run ); } ``` </p> </details> I can also add more micro benchmarks as a follow on task in https://github.com/apache/arrow-rs/blob/master/arrow/benches/csv_reader.rs if it's necessary. <!-- Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed. Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes. --> # What changes are included in this PR? Adding one type branch in `arrow-csv`'s parsing logic <!-- There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR. --> # Are there any user-facing changes? No <!-- If there are user-facing changes then we may require documentation to be updated before approving the PR. --> <!--- If there are any breaking changes to public APIs, please add the `breaking change` label. --> -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
