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 2022/03/15 07:41:00 UTC

[GitHub] [arrow-rs] alamb commented on a change in pull request #1444: Add Full UnionArray validation

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



##########
File path: arrow/src/array/data.rs
##########
@@ -1117,6 +1119,44 @@ impl ArrayData {
         )
     }
 
+    /// Ensures that for each union element, the offset is correct for
+    /// the corresponding child array
+    fn validate_dense_union_full(&self) -> Result<()> {
+        // safety justification is that the size of the buffers was validated in self.validate()
+        let type_ids = self.typed_offsets::<i8>(&self.buffers[0])?;
+        let offsets = self.typed_offsets::<i32>(&self.buffers[1])?;
+
+        type_ids.iter().enumerate().try_for_each(|(i, &type_id)| {
+            // this will panic if out of bounds. Could make a nicer error message
+            let type_id: usize = type_id
+                .try_into()
+                .map_err(|_| {
+                    ArrowError::InvalidArgumentError(format!(
+                        "Offset invariant failure: Could not convert type id {} to usize in slot {}",
+                        type_id, i))
+                })?;
+
+            let num_children = self.child_data[type_id].len();
+            let child_offset: usize = offsets[i]
+                .try_into()
+                .map_err(|_| {
+                    ArrowError::InvalidArgumentError(format!(
+                        "Offset invariant failure: Could not convert offset {} at position {} to usize",
+                        offsets[i], i))
+                })?;
+
+
+            if child_offset >= num_children {
+                Err(ArrowError::InvalidArgumentError(format!(
+                    "Value at position {} out of bounds: {} (child array {} length is {})",

Review comment:
       ```suggestion
                       "Offset at position {} out of bounds: {} (child array {} length is {})",
   ```




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