You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/12/07 22:10:25 UTC

[GitHub] [arrow] Dandandan commented on a change in pull request #8829: ARROW-10804: Removed unsafe from parquet, causing a compilation error.

Dandandan commented on a change in pull request #8829:
URL: https://github.com/apache/arrow/pull/8829#discussion_r537870768



##########
File path: rust/parquet/src/arrow/record_reader.rs
##########
@@ -340,42 +297,41 @@ impl<T: DataType> RecordReader<T> {
         }
 
         // Convert mutable buffer spaces to mutable slices
-        let mut values_buf = FatPtr::<T::T>::with_offset_and_size(
-            &mut self.records,
-            self.values_written,
-            T::get_type_size(),
-        );
+        let (prefix, values, suffix) = unsafe { self.records.data_mut().align_to_mut::<T::T>() };
+        assert!(prefix.is_empty() && suffix.is_empty());
+        let values = &mut values[self.values_written..];
 
         let values_written = self.values_written;
-        let mut def_levels_buf = self
+        let def_levels = self
             .def_levels
             .as_mut()
-            .map(|buf| FatPtr::<i16>::with_offset(buf, values_written));
+            .map(|buf| {
+                let (prefix, values, suffix) = unsafe { buf.data_mut().align_to_mut::<i16>() };
+                assert!(prefix.is_empty() && suffix.is_empty());
+                &mut values[values_written..]
+            });
 
-        let mut rep_levels_buf = self
+        let rep_levels = self
             .rep_levels
             .as_mut()
-            .map(|buf| FatPtr::<i16>::with_offset(buf, values_written));
+            .map(|buf| {
+                let (prefix, values, suffix) = unsafe { buf.data_mut().align_to_mut::<i16>() };
+                assert!(prefix.is_empty() && suffix.is_empty());
+                &mut values[values_written..]
+            });
 
         let (values_read, levels_read) =
             self.column_reader.as_mut().unwrap().read_batch(
                 batch_size,
-                def_levels_buf.as_mut().map(|ptr| ptr.to_slice_mut()),
-                rep_levels_buf.as_mut().map(|ptr| ptr.to_slice_mut()),
-                values_buf.to_slice_mut(),
+                def_levels,

Review comment:
       The error originates from here, the error shows that it is moved here. A clone likely "solves" the issue? Usually taking the value by `&` in the function also solves this as it will stop it from taking ownership?




----------------------------------------------------------------
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:
users@infra.apache.org