Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
andygrove committed Jun 11, 2024
1 parent 805ae8f commit 5687df9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ criterion = "0.5.1"
jni = { version = "0.21", features = ["invocation"] }
lazy_static = "1.4"
assertables = "7"
hex = "0.4.3"


[features]
default = []
Expand Down
34 changes: 34 additions & 0 deletions core/src/parquet/read/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -978,3 +978,37 @@ impl Decoder for DictDecoder {
Encoding::RLE_DICTIONARY
}
}

fn copy_i32_to_i16(src: &[u8], dst: &mut [u8], num: usize) {
let mut src_offset = 0;
let mut dst_offset = 0;
for _ in 0..num {
unsafe {
copy_nonoverlapping(
&src[src_offset..] as *const [u8] as *const u8 as *const i16,
&mut dst[dst_offset] as *mut u8 as *mut i16,
1,
);
}
src_offset += 4; // Parquet stores Int8/Int16 using 4 bytes
dst_offset += 2;
}
}

#[cfg(test)]
mod test {
use super::copy_i32_to_i16;
use parquet::data_type::AsBytes;

#[test]
fn test_i32_to_i16() {
let source =
hex::decode("8a0e0000db93ffff1826000034f4ffff300200001d2b0000abe3ffff378dfffff1470000")
.unwrap();
let expected = hex::decode("8a0edb93182634f430021d2babe3378df147").unwrap();
let num = source.len() / 4;
let mut dest: Vec<u8> = vec![b' '; num * 2];
copy_i32_to_i16(&source.as_bytes(), dest.as_mut_slice(), num);
assert_eq!(expected.as_bytes(), dest.as_bytes());
}
}

0 comments on commit 5687df9

Please sign in to comment.