You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "alamb (via GitHub)" <gi...@apache.org> on 2023/05/24 19:52:22 UTC

[GitHub] [arrow-rs] alamb commented on a diff in pull request #4263: Add constructors for FixedSize array types (#3879)

alamb commented on code in PR #4263:
URL: https://github.com/apache/arrow-rs/pull/4263#discussion_r1204686679


##########
arrow-array/src/array/fixed_size_list_array.rs:
##########
@@ -68,6 +69,114 @@ pub struct FixedSizeListArray {
 }
 
 impl FixedSizeListArray {
+    /// Create a new [`FixedSizeListArray`] with `size` element size, panicking on failure
+    ///
+    /// # Panics
+    ///
+    /// Panics if [`Self::try_new`] returns an error
+    pub fn new(
+        field: FieldRef,
+        size: i32,
+        values: ArrayRef,
+        nulls: Option<NullBuffer>,
+    ) -> Self {
+        Self::try_new(field, size, values, nulls).unwrap()
+    }
+
+    /// Create a new [`FixedSizeListArray`] from the provided parts, returning an error on failure
+    ///
+    /// # Errors
+    ///
+    /// * `size < 0`
+    /// * `values.len() / size != nulls.len()`
+    /// * `values.data_type() != field.data_type()`
+    /// * `!field.is_nullable() && !nulls.expand(size).contains(values.nulls())`
+    pub fn try_new(
+        field: FieldRef,
+        size: i32,

Review Comment:
   I think naming this parameter `value_length` to align with the field name would make it easier to understand



##########
arrow-data/src/data/mod.rs:
##########
@@ -1152,40 +1151,17 @@ impl ArrayData {
                     match &self.nulls {
                         Some(nulls) => {
                             let element_len = *len as usize;
-                            let mut buffer =
-                                MutableBuffer::new_null(element_len * self.len);
-
-                            // Expand each bit within `null_mask` into `element_len`
-                            // bits, constructing the implicit mask of the child elements
-                            for i in 0..self.len {
-                                if nulls.is_null(i) {
-                                    continue;
-                                }
-                                for j in 0..element_len {
-                                    bit_util::set_bit(
-                                        buffer.as_mut(),
-                                        i * element_len + j,
-                                    )
-                                }
-                            }
-                            let mask = buffer.into();
-                            self.validate_non_nullable(Some(&mask), 0, child)?;
+                            let expanded = nulls.expand(element_len);

Review Comment:
   this is a nice cleanup



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org