GregBowyer commented on a change in pull request #8698:
URL: https://github.com/apache/arrow/pull/8698#discussion_r534654706
##########
File path: rust/parquet/src/data_type.rs
##########
@@ -583,32 +740,198 @@ pub(crate) mod private {
impl_from_raw!(f64, self => { Err(general_err!("Type cannot be converted
to i64")) });
impl ParquetValueType for super::Int96 {
- fn encoded(&self) -> EncodedValue<'_> {
- EncodedValue::Bytes { data: self.as_bytes() }
+ #[inline]
+ fn encode<W: std::io::Write>(values: &[Self], writer: &mut W, _: &mut
BitWriter) -> Result<()> {
+ for value in values {
+ let raw = unsafe {
+ std::slice::from_raw_parts(value.data() as *const [u32] as
*const u8, 12)
+ };
+ writer.write_all(raw)?;
+ }
+ Ok(())
}
+ #[inline]
+ fn set_data(decoder: &mut PlainDecoderDetails, data: ByteBufferPtr,
num_values: usize) {
+ decoder.data.replace(data);
+ decoder.start = 0;
+ decoder.num_values = num_values;
+ }
+
+ #[inline]
+ fn decode(buffer: &mut [Self], decoder: &mut PlainDecoderDetails) ->
Result<usize> {
+ // TODO - Remove the duplication between this and the general
slice method
+ let data = decoder.data.as_ref().expect("set_data should have been
called");
Review comment:
Performance notes:
This code is lifted from elsewhere so its useful to state out loud what
change was made.
Other than a small amount of shuffling the code about for general style, A
lot of the pre-existing code has a pattern of the form
```rust
assert!(self.some_option.is_some())
let some_option = self.some_option.unwrap()
```
This unfortunately is not spotted by the compiler and seems to generate
multiple branches that just consume CPU cycles.
Since the validations are useful, in this (and many places) the logic is
folded into doing an unwrap (with a little more error messaging to state what
invariant is being tested for)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]