Rich-T-kid commented on code in PR #11912:
URL: https://github.com/apache/arrow-rs/pull/11912#discussion_r4404201865


##########
arrow-data/src/transform/list_view.rs:
##########
@@ -29,6 +30,17 @@ pub(super) fn build_extend<T: ArrowNativeType + Integer + 
CheckedAdd>(
     let sizes = array.buffer::<T>(1);
     Box::new(
         move |mutable: &mut _MutableArrayData, index: usize, start: usize, 
len: usize| {
+            let additional = len
+                .checked_mul(size_of::<T>())
+                .ok_or_else(|| ArrowError::MemoryError("list-view buffer size 
overflow".into()))?;
+            mutable
+                .buffer1
+                .try_reserve(additional)
+                .map_err(|e| ArrowError::MemoryError(e.to_string()))?;
+            mutable
+                .buffer2
+                .try_reserve(additional)
+                .map_err(|e| ArrowError::MemoryError(e.to_string()))?;

Review Comment:
   Removed the separate capacity calculation and now use fallible buffer writes 
directly in 4911a8a3e7.



##########
arrow-row/src/fixed.rs:
##########
@@ -356,16 +356,19 @@ fn split_off<'a>(src: &mut &'a [u8], len: usize) -> &'a 
[u8] {
 }
 
 /// Decodes a `BooleanArray` from rows
-pub fn decode_bool(rows: &mut [&[u8]], options: SortOptions) -> BooleanArray {
+pub fn decode_bool(rows: &mut [&[u8]], options: SortOptions) -> 
Result<BooleanArray, ArrowError> {

Review Comment:
   Kept the existing return type and moved the fallible path to an internal 
try_decode_bool helper in 4911a8a3e7.



##########
arrow-row/src/fixed.rs:
##########
@@ -402,30 +405,35 @@ pub fn decode_bool(rows: &mut [&[u8]], options: 
SortOptions) -> BooleanArray {
     let nulls = NullBuffer::new(BooleanBuffer::new(nulls.into(), 0, len));
     let nulls = (nulls.null_count() > 0).then_some(nulls);
 
-    BooleanArray::new(BooleanBuffer::new(values.into(), 0, len), nulls)
+    Ok(BooleanArray::new(
+        BooleanBuffer::new(values.into(), 0, len),
+        nulls,
+    ))
 }
 
 /// Decodes a single byte from each row, interpreting `0x01` as a valid value
 /// and all other values as a null. Optionally returns `None` if there are no
 /// null values.
-pub fn decode_nulls(rows: &[&[u8]]) -> Option<NullBuffer> {
-    let nulls = BooleanBuffer::collect_bool(rows.len(), |idx| rows[idx][0] == 
1);
+pub fn decode_nulls(rows: &[&[u8]]) -> Result<Option<NullBuffer>, ArrowError> {

Review Comment:
   Kept the existing return type and moved the fallible path to an internal 
try_decode_nulls helper in 4911a8a3e7.



##########
arrow-row/src/fixed.rs:
##########
@@ -402,30 +405,35 @@ pub fn decode_bool(rows: &mut [&[u8]], options: 
SortOptions) -> BooleanArray {
     let nulls = NullBuffer::new(BooleanBuffer::new(nulls.into(), 0, len));
     let nulls = (nulls.null_count() > 0).then_some(nulls);
 
-    BooleanArray::new(BooleanBuffer::new(values.into(), 0, len), nulls)
+    Ok(BooleanArray::new(
+        BooleanBuffer::new(values.into(), 0, len),
+        nulls,
+    ))
 }
 
 /// Decodes a single byte from each row, interpreting `0x01` as a valid value
 /// and all other values as a null. Optionally returns `None` if there are no
 /// null values.
-pub fn decode_nulls(rows: &[&[u8]]) -> Option<NullBuffer> {
-    let nulls = BooleanBuffer::collect_bool(rows.len(), |idx| rows[idx][0] == 
1);
+pub fn decode_nulls(rows: &[&[u8]]) -> Result<Option<NullBuffer>, ArrowError> {
+    let nulls = MutableBuffer::try_collect_bool(rows.len(), |idx| rows[idx][0] 
== 1)
+        .map_err(|e| ArrowError::MemoryError(e.to_string()))?;
+    let nulls = BooleanBuffer::new(nulls.into(), 0, rows.len());
     let nulls = NullBuffer::new(nulls);
-    (nulls.null_count() > 0).then_some(nulls)
+    Ok((nulls.null_count() > 0).then_some(nulls))
 }
 
 /// Decodes a `PrimitiveArray` from rows
 pub fn decode_primitive<T: ArrowPrimitiveType>(

Review Comment:
   Kept the existing return type and moved the fallible path to an internal 
try_decode_primitive helper in 4911a8a3e7.



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