tustvold commented on code in PR #3553:
URL: https://github.com/apache/arrow-rs/pull/3553#discussion_r1086442734


##########
arrow-data/src/data.rs:
##########
@@ -1446,6 +1493,50 @@ impl ArrayData {
         })
     }
 
+    /// Validates that each value in run_ends array is positive and strictly 
increasing.
+    fn check_run_ends<T>(&self, array_len: usize) -> Result<(), ArrowError>
+    where
+        T: ArrowNativeType + TryInto<i64> + num::Num + std::fmt::Display,
+    {
+        let values = self.typed_buffer::<T>(0, self.len())?;
+        let mut prev_value: i64 = 0_i64;
+        values.iter().enumerate().try_for_each(|(ix, &inp_value)| {
+            let value: i64 = inp_value.try_into().map_err(|_| {
+                ArrowError::InvalidArgumentError(format!(
+                    "Value at position {} out of bounds: {} (can not convert 
to i64)",
+                    ix, inp_value
+                ))
+            })?;
+            if value <= 0_i64 {
+                return Err(ArrowError::InvalidArgumentError(format!(
+                    "The values in run_ends array should be strictly positive. 
Found value {} at index {} that does not match the criteria.",
+                    value,
+                    ix
+                )));
+            }
+            if ix > 0 && value <= prev_value {
+                return Err(ArrowError::InvalidArgumentError(format!(
+                    "The values in run_ends array should be strictly 
increasing. Found value {} at index {} with previous value {} that does not 
match the criteria.",
+                    value,
+                    ix,
+                    prev_value
+                )));
+            }
+
+            prev_value = value;
+            Ok(())
+        })?;
+
+        if prev_value.as_usize() != array_len {

Review Comment:
   `self.len` returns the logical length, as per the specification. This is one 
of the reasons run ends is stored as a child array, so that the parent length 
can be the logical length



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