Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Added support for reading binary from CSV #337

Merged
merged 1 commit into from Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/io/csv/read/deserialize.rs
Expand Up @@ -58,6 +58,11 @@ fn deserialize_utf8<O: Offset>(rows: &[ByteRecord], column: usize) -> Arc<dyn Ar
Arc::new(Utf8Array::<O>::from_trusted_len_iter(iter))
}

fn deserialize_binary<O: Offset>(rows: &[ByteRecord], column: usize) -> Arc<dyn Array> {
let iter = rows.iter().map(|row| row.get(column));
Arc::new(BinaryArray::<O>::from_trusted_len_iter(iter))
}

pub fn deserialize_column(
rows: &[ByteRecord],
column: usize,
Expand Down Expand Up @@ -151,6 +156,8 @@ pub fn deserialize_column(
}
Utf8 => deserialize_utf8::<i32>(rows, column),
LargeUtf8 => deserialize_utf8::<i64>(rows, column),
Binary => deserialize_binary::<i32>(rows, column),
LargeBinary => deserialize_binary::<i64>(rows, column),
other => {
return Err(ArrowError::NotYetImplemented(format!(
"Deserializing type \"{:?}\" is not implemented",
Expand Down
12 changes: 12 additions & 0 deletions tests/it/io/csv/read.rs
Expand Up @@ -173,3 +173,15 @@ fn float32() -> Result<()> {
assert_eq!(expected, result.as_ref());
Ok(())
}

#[test]
fn binary() -> Result<()> {
let input = vec!["aa", "bb"];
let input = input.join("\n");

let expected = BinaryArray::<i32>::from([Some(b"aa"), Some(b"bb")]);

let result = test_deserialize(&input, DataType::Binary)?;
assert_eq!(expected, result.as_ref());
Ok(())
}