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

Commit

Permalink
Added support for reading binary from CSV (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao authored Aug 25, 2021
1 parent f79ae3e commit a52211d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/io/csv/read/deserialize.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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(())
}

0 comments on commit a52211d

Please sign in to comment.