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

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Jorge Leitao <[email protected]>
  • Loading branch information
danburkert and jorgecarleitao authored Jan 11, 2022
1 parent cf79676 commit 3e7b85c
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/io/parquet/read/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,20 +327,23 @@ fn page_iter_to_array<I: FallibleStreamingIterator<Item = DataPage, Error = Parq
DataType::FixedSizeBinary(n),
metadata,
)?;
let i128_values =
let values =
fixed_size_binary_array
.into_iter()
.map(|value: Option<&[u8]>| {
.values()
.iter()
.map(|value: &[u8]| {
// Copy the fixed-size byte value to the start of a 16 byte stack
// allocated buffer, then use an arithmetic right shift to fill in
// MSBs, which accounts for leading 1's in negative (two's complement)
// values.
let mut bytes = [0u8; 16];
bytes[..n].copy_from_slice(value?);
Some(i128::from_be_bytes(bytes) >> 8 * (16 - n))
});
let i128_array = PrimitiveArray::<i128>::from_iter(i128_values);
Ok(Box::new(i128_array.to(data_type)) as _)
bytes[..n].copy_from_slice(value);
i128::from_be_bytes(bytes) >> 8 * (16 - n)
})
.collect::<Vec<_>>();
let validity = fixed_size_binary_array.validity().cloned();
let i128_array = PrimitiveArray::<i128>::from_data(data_type, values.into(), validity);
Ok(Box::new(i128_array) as _)
}
_ => unreachable!(),
},
Expand Down

0 comments on commit 3e7b85c

Please sign in to comment.