alamb commented on a change in pull request #779:
URL: https://github.com/apache/arrow-rs/pull/779#discussion_r710519807
##########
File path: parquet/src/arrow/converter.rs
##########
@@ -167,6 +168,46 @@ impl Converter<Vec<Option<FixedLenByteArray>>,
IntervalDayTimeArray>
}
}
+/// An Arrow Interval converter, which reads the last 16 bytes of a Parquet
interval,
+/// and interprets it as an i128 value representing the Arrow MonthDayNano
value
+pub struct IntervalMonthDayNanoArrayConverter {}
+
+impl IntervalMonthDayNanoArrayConverter {
+ fn from_bytes_to_i128(b: &[u8]) -> i128 {
+ assert!(
+ b.len() <= 16,
+ "IntervalMonthDayNanoArray supports only up to size 16"
+ );
+ let first_bit = b[0] & 128u8 == 128u8;
+ let mut result = if first_bit { [255u8; 16] } else { [0u8; 16] };
+ for (i, v) in b.iter().enumerate() {
+ result[i + (16 - b.len())] = *v;
+ }
+ i128::from_be_bytes(result)
+ }
+}
+
+impl Converter<Vec<Option<FixedLenByteArray>>, IntervalMonthDayNanoArray>
+ for IntervalMonthDayNanoArrayConverter
+{
+ fn convert(
+ &self,
+ source: Vec<Option<FixedLenByteArray>>,
+ ) -> Result<IntervalMonthDayNanoArray> {
+ let mut builder = IntervalMonthDayNanoBuilder::new(source.len());
+ for v in source {
+ match v {
+ Some(array) => {
+
builder.append_value(Self::from_bytes_to_i128(array.data()))
+ }
+ None => builder.append_null(),
+ }?
+ }
+
+ Ok(builder.finish())
+ }
+}
+
Review comment:
I wonder if it would be possible to implement some tests for this logic
(showing for example that round tripping from `IntervalMonthDayNanoArray` to
`FixedLenByteArray` and back produces an equivalent array?
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]