alamb commented on a change in pull request #822:
URL: https://github.com/apache/arrow-rs/pull/822#discussion_r725500478



##########
File path: arrow/src/array/data.rs
##########
@@ -264,6 +278,53 @@ impl ArrayData {
         }
     }
 
+    /// Create a new ArrayData, validating that the provided buffers
+    /// form a valid Arrow array of the specified data type.
+    ///
+    /// If `null_count` is not specified, the number of nulls in
+    /// null_bit_buffer is calculated
+    ///
+    /// Note: This is a low level API and most users of the arrow
+    /// crate should create arrays using the methods in the `array`
+    /// module.
+    pub fn try_new(
+        data_type: DataType,
+        len: usize,
+        null_count: Option<usize>,
+        null_bit_buffer: Option<Buffer>,
+        offset: usize,
+        buffers: Vec<Buffer>,
+        child_data: Vec<ArrayData>,
+    ) -> Result<Self> {
+        // Safetly justification: `validate` is (will be) called below
+        let new_self = unsafe {
+            Self::new_unchecked(
+                data_type,
+                len,
+                null_count,
+                null_bit_buffer,
+                offset,
+                buffers,
+                child_data,
+            )
+        };
+
+        new_self.validate()?;
+        Ok(new_self)
+    }
+
+    /// Validates that buffers in this ArrayData are sufficiently
+    /// sized, to store `len` + `offset` total elements of
+    /// `data_type`.
+    ///
+    /// This check is "cheap" in the sense that it does not validate the
+    /// contents of the buffers (e.g. that string offsets for UTF8 arrays
+    /// are within the length of the buffer).
+    pub fn validate(&self) -> Result<()> {
+        // will be filled in a subsequent PR

Review comment:
       https://github.com/apache/arrow-rs/pull/810 has an initial set of checks

##########
File path: arrow/src/array/data.rs
##########
@@ -264,6 +278,53 @@ impl ArrayData {
         }
     }
 
+    /// Create a new ArrayData, validating that the provided buffers

Review comment:
       The API changes in `data.rs` are the core changes in this PR -- 
everything else is a mechanical changes to use the new APIs. 




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