alamb commented on code in PR #13758:
URL: https://github.com/apache/datafusion/pull/13758#discussion_r1884130028


##########
datafusion/functions/src/strings.rs:
##########
@@ -185,7 +185,21 @@ impl StringArrayBuilder {
         unsafe { self.offsets_buffer.push_unchecked(next_offset) };
     }
 
+    /// Finalise the builder into a concrete [`StringArray`].
+    ///
+    /// # Panics
+    ///
+    /// This method can panic when:
+    ///
+    /// - the provided `null_buffer` is not the same length as the 
`offsets_buffer`.
     pub fn finish(self, null_buffer: Option<NullBuffer>) -> StringArray {
+        if let Some(ref null_buffer) = null_buffer {
+            assert_eq!(
+                null_buffer.len(),
+                self.offsets_buffer.len() / size_of::<i32>() - 1,

Review Comment:
    A minor nit: it would be nice to pull
   ```rust
   self.offsets_buffer.len() / size_of::<i32>() - 1,
   ```
   
   Into its own variable so there is less of a chance the check and the code 
that uses it below are out of sync
   
   ```rust
   let row_count = self.offsets_buffer.len() / size_of::<i32>() - 1;
   assert_eq!(null_buffer.len(), row_count)
   
   array_builder = ArrayDataBuilder::new(DataType::Utf8)
               .len(row_count)
   ...
   ```
   
   



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to