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

Commit

Permalink
Fixed error
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed May 30, 2022
1 parent 8d896e8 commit b18896c
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/ffi/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,13 @@ fn buffer_offset(array: &ArrowArray, data_type: &DataType, i: usize) -> usize {
use PhysicalType::*;
match (data_type.to_physical_type(), i) {
(LargeUtf8, 2) | (LargeBinary, 2) | (Utf8, 2) | (Binary, 2) => 0,
(FixedSizeBinary, 1) => {
if let DataType::FixedSizeBinary(size) = data_type.to_logical_type() {
(array.offset as usize) * *size
} else {
unreachable!()
}
}
_ => array.offset as usize,
}
}
Expand Down
1 change: 1 addition & 0 deletions src/ffi/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ unsafe fn to_data_type(schema: &ArrowSchema) -> Result<DataType> {
let size = size_raw
.parse::<usize>()
.map_err(|_| Error::OutOfSpec("size is not a valid integer".to_string()))?;
println!("schema: {}", size);
DataType::FixedSizeBinary(size)
}
["+w", size_raw] => {
Expand Down
54 changes: 53 additions & 1 deletion tests/it/ffi/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@ fn u32() -> Result<()> {
test_round_trip(data)
}

#[test]
fn decimal() -> Result<()> {
let data = Int128Array::from_slice(&[1, 0, 2, 0]);
test_round_trip(data)
}

#[test]
fn decimal_nullable() -> Result<()> {
let data = Int128Array::from(&[Some(1), None, Some(2), None]);
test_round_trip(data)
}

#[test]
fn timestamp_tz() -> Result<()> {
let data = Int64Array::from(&vec![Some(2), None, None]).to(DataType::Timestamp(
Expand Down Expand Up @@ -128,6 +140,26 @@ fn large_binary() -> Result<()> {
test_round_trip(data)
}

#[test]
fn fixed_size_binary() -> Result<()> {
let data = FixedSizeBinaryArray::new(
DataType::FixedSizeBinary(2),
vec![1, 2, 3, 4, 5, 6].into(),
None,
);
test_round_trip(data)
}

#[test]
fn fixed_size_binary_nullable() -> Result<()> {
let data = FixedSizeBinaryArray::new(
DataType::FixedSizeBinary(2),
vec![1, 2, 3, 4, 5, 6].into(),
Some([true, true, false].into()),
);
test_round_trip(data)
}

#[test]
fn list() -> Result<()> {
let data = vec![
Expand All @@ -144,6 +176,22 @@ fn list() -> Result<()> {
test_round_trip(array)
}

#[test]
fn large_list() -> Result<()> {
let data = vec![
Some(vec![Some(1i32), Some(2), Some(3)]),
None,
Some(vec![Some(4), None, Some(6)]),
];

let mut array = MutableListArray::<i64, MutablePrimitiveArray<i32>>::new();
array.try_extend(data)?;

let array: ListArray<i64> = array.into();

test_round_trip(array)
}

#[test]
fn fixed_list() -> Result<()> {
let data = vec![
Expand Down Expand Up @@ -231,7 +279,11 @@ fn schema() -> Result<()> {
fn extension() -> Result<()> {
let field = Field::new(
"a",
DataType::Extension("a".to_string(), Box::new(DataType::Int32), None),
DataType::Extension(
"a".to_string(),
Box::new(DataType::Int32),
Some("bla".to_string()),
),
true,
);
test_round_trip_schema(field)
Expand Down

0 comments on commit b18896c

Please sign in to comment.