Skip to content

Commit

Permalink
fix: Use bytemuck in slice reinterpret for Parquet ArrayChunks (#17700)
Browse files Browse the repository at this point in the history
  • Loading branch information
coastalwhite authored Jul 18, 2024
1 parent 05d4703 commit 235cad3
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/polars-parquet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ description = "Apache Parquet I/O operations for Polars"
ahash = { workspace = true }
arrow = { workspace = true, features = ["io_ipc"] }
base64 = { workspace = true }
bytemuck = { workspace = true }
ethnum = { workspace = true }
fallible-streaming-iterator = { workspace = true, optional = true }
futures = { workspace = true, optional = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ impl<'a, P: ParquetNativeType> ArrayChunks<'a, P> {
return None;
}

// SAFETY:
// We know that that the alignment, size and provenance are the same.
let bytes = unsafe { std::mem::transmute::<&[u8], &[P::Bytes]>(bytes) };
let bytes = bytemuck::cast_slice(bytes);

Some(Self { bytes })
}
Expand Down
1 change: 1 addition & 0 deletions crates/polars-parquet/src/parquet/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::parquet::schema::types::PhysicalType;
/// A physical native representation of a Parquet fixed-sized type.
pub trait NativeType: std::fmt::Debug + Send + Sync + 'static + Copy + Clone {
type Bytes: AsRef<[u8]>
+ bytemuck::Pod
+ for<'a> TryFrom<&'a [u8], Error = std::array::TryFromSliceError>
+ std::fmt::Debug
+ Clone
Expand Down

0 comments on commit 235cad3

Please sign in to comment.