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

Evaluate null_regex for string type in csv (now such values will be parsed as Null rather than "") #4942

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Changes from 1 commit
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
18 changes: 12 additions & 6 deletions arrow-csv/src/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,14 @@ fn parse(
}
DataType::Utf8 => Ok(Arc::new(
rows.iter()
.map(|row| Some(row.get(i)))
.map(|row| {
let s = row.get(i);
if null_regex.is_null(s) {
None
} else {
Some(s)
}
haohuaijin marked this conversation as resolved.
Show resolved Hide resolved
})
.collect::<StringArray>(),
) as ArrayRef),
DataType::Dictionary(key_type, value_type)
Expand Down Expand Up @@ -1495,7 +1502,7 @@ mod tests {
let schema = Arc::new(Schema::new(vec![
Field::new("c_int", DataType::UInt64, false),
Field::new("c_float", DataType::Float32, true),
Field::new("c_string", DataType::Utf8, false),
Field::new("c_string", DataType::Utf8, true),
Field::new("c_bool", DataType::Boolean, false),
]));

Expand Down Expand Up @@ -1596,8 +1603,7 @@ mod tests {
assert!(batch.column(0).is_null(1));
assert!(batch.column(1).is_null(2));
assert!(batch.column(3).is_null(4));
// String won't be empty
assert!(!batch.column(2).is_null(3));
assert!(batch.column(2).is_null(3));
assert!(!batch.column(2).is_null(4));
}

Expand Down Expand Up @@ -2237,8 +2243,8 @@ mod tests {

fn err_test(csv: &[u8], expected: &str) {
let schema = Arc::new(Schema::new(vec![
Field::new("text1", DataType::Utf8, false),
Field::new("text2", DataType::Utf8, false),
Field::new("text1", DataType::Utf8, true),
Field::new("text2", DataType::Utf8, true),
]));
let buffer = std::io::BufReader::with_capacity(2, Cursor::new(csv));
let b = ReaderBuilder::new(schema)
Expand Down
Loading