tustvold commented on code in PR #4681:
URL: https://github.com/apache/arrow-rs/pull/4681#discussion_r1291207929


##########
arrow-ipc/src/reader.rs:
##########
@@ -231,83 +230,28 @@ fn create_primitive_array(
                 .len(length)
                 .buffers(buffers[1..3].to_vec())
                 .null_bit_buffer(null_buffer)
-                .build()?
+                .build_aligned()?
         }
-        Int8
-        | Int16
-        | Int32
-        | UInt8
-        | UInt16
-        | UInt32
-        | Time32(_)
-        | Date32
-        | Interval(IntervalUnit::YearMonth)
-        | Interval(IntervalUnit::DayTime)
-        | FixedSizeBinary(_)
-        | Boolean
-        | Int64
-        | UInt64
-        | Float32
-        | Float64
-        | Time64(_)
-        | Timestamp(_, _)
-        | Date64
-        | Duration(_) => {
+        _ if data_type.is_primitive()
+            || matches!(data_type, Boolean | FixedSizeBinary(_)) =>
+        {
             // read 2 buffers: null buffer (optional) and data buffer
             ArrayData::builder(data_type.clone())
                 .len(length)
                 .add_buffer(buffers[1].clone())
                 .null_bit_buffer(null_buffer)
-                .build()?
-        }
-        Interval(IntervalUnit::MonthDayNano) | Decimal128(_, _) => {
-            let buffer = get_aligned_buffer::<i128>(&buffers[1], length);
-
-            // read 2 buffers: null buffer (optional) and data buffer
-            ArrayData::builder(data_type.clone())
-                .len(length)
-                .add_buffer(buffer)
-                .null_bit_buffer(null_buffer)
-                .build()?
-        }
-        Decimal256(_, _) => {
-            let buffer = get_aligned_buffer::<i256>(&buffers[1], length);
-
-            // read 2 buffers: null buffer (optional) and data buffer
-            ArrayData::builder(data_type.clone())
-                .len(length)
-                .add_buffer(buffer)
-                .null_bit_buffer(null_buffer)
-                .build()?
+                .build_aligned()?
         }
         t => unreachable!("Data type {:?} either unsupported or not 
primitive", t),
     };
 
     Ok(make_array(array_data))
 }
 
-/// Checks if given `Buffer` is properly aligned with `T`.
-/// If not, copying the data and padded it for alignment.
-fn get_aligned_buffer<T>(buffer: &Buffer, length: usize) -> Buffer {

Review Comment:
   This was originally added because aarch64 has stronger alignment 
requirements for i128 than the 64-bit alignment commonly provided by 
flatbuffers, now this is handled systematically for all types



-- 
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]

Reply via email to