alamb commented on a change in pull request #8303:
URL: https://github.com/apache/arrow/pull/8303#discussion_r497405581



##########
File path: rust/arrow/src/compute/kernels/filter.rs
##########
@@ -353,15 +353,19 @@ impl FilterContext {
                         // foreach bit in batch:
                         if (filter_batch & self.filter_mask[j]) != 0 {
                             let data_index = (i * 64) + j;
-                            values.push(input_array.value(data_index));
+                            if input_array.is_null(data_index) {
+                                values.push(None)
+                            } else {
+                                
values.push(Some(input_array.value(data_index)))
+                            }
                         }
                     }
                 }
                 Ok(Arc::new(BinaryArray::from(values)))
             }
             DataType::Utf8 => {
                 let input_array = 
array.as_any().downcast_ref::<StringArray>().unwrap();
-                let mut values: Vec<&str> = 
Vec::with_capacity(self.filtered_count);
+                let mut values: Vec<Option<&str>> = 
Vec::with_capacity(self.filtered_count);

Review comment:
       > Doesn't an Option of a reference leverages null pointer optimization 
(on which None is represented by the null pointer, e.g. rust-lang/rust#9378)?
   
   Yes, I believe you are correct.
   
   This program:
   ```
   fn main() {
       println!("The size of a &str is {}", std::mem::size_of::<&str>());
       println!("The size of an Option<&str> is {}", 
std::mem::size_of::<Option<&str>>());
   }
   ```
   
   Produces the following on my machine:
   ```
   The size of a &str is 16
   The size of an Option<&str> is 16
   ```
   
   

##########
File path: rust/arrow/src/array/array.rs
##########
@@ -1267,6 +1267,36 @@ impl<OffsetSize: OffsetSizeTrait> 
GenericBinaryArray<OffsetSize> {
         GenericBinaryArray::<OffsetSize>::from(array_data)
     }
 
+    fn from_opt_vec(v: Vec<Option<&[u8]>>, data_type: DataType) -> Self {

Review comment:
       It is tested (indirectly) in 
https://github.com/apache/arrow/pull/8303/files#diff-d7b0b7cde1850e8744ceda458c6dea81R700
 -- but I think a more specific test would be valuable. I will add one. 




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


Reply via email to