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


##########
parquet/src/arrow/arrow_writer/mod.rs:
##########
@@ -399,48 +415,35 @@ fn write_leaf(
     let indices = levels.non_null_indices();
     let written = match writer {
         ColumnWriter::Int32ColumnWriter(ref mut typed) => {
-            let values = match column.data_type() {
+            match column.data_type() {
                 ArrowDataType::Date64 => {
                     // If the column is a Date64, we cast it to a Date32, and 
then interpret that as Int32
-                    let array = if let ArrowDataType::Date64 = 
column.data_type() {
-                        let array = arrow::compute::cast(column, 
&ArrowDataType::Date32)?;
-                        arrow::compute::cast(&array, &ArrowDataType::Int32)?
-                    } else {
-                        arrow::compute::cast(column, &ArrowDataType::Int32)?
-                    };
+                    let array = arrow::compute::cast(column, 
&ArrowDataType::Date32)?;
+                    let array = arrow::compute::cast(&array, 
&ArrowDataType::Int32)?;
+
                     let array = array
                         .as_any()
                         .downcast_ref::<arrow_array::Int32Array>()
                         .expect("Unable to get int32 array");
-                    get_numeric_array_slice::<Int32Type, _>(array, indices)
+                    write_primitive(typed, array.values(), levels)?
                 }
                 ArrowDataType::UInt32 => {
+                    let data = column.data();
+                    let offset = data.offset();
                     // follow C++ implementation and use overflow/reinterpret 
cast from  u32 to i32 which will map
                     // `(i32::MAX as u32)..u32::MAX` to `i32::MIN..0`
-                    let array = column
-                        .as_any()
-                        .downcast_ref::<arrow_array::UInt32Array>()
-                        .expect("Unable to get u32 array");
-                    let array = arrow::compute::unary::<_, _, 
arrow::datatypes::Int32Type>(
-                        array,
-                        |x| x as i32,
-                    );
-                    get_numeric_array_slice::<Int32Type, _>(&array, indices)
+                    let array: &[i32] = data.buffers()[0].typed_data();

Review Comment:
   Yup, this simply reinterprets the bytes without modification, same as C++'s 
reinterpret cast. This will result in the upper unsigned range being mapped to 
the 2s complement range of the signed representation.



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