scovich commented on code in PR #9610:
URL: https://github.com/apache/arrow-rs/pull/9610#discussion_r3003375058


##########
parquet-variant-compute/src/variant_array.rs:
##########
@@ -957,9 +985,8 @@ fn typed_value_to_variant<'a>(
             let value = array.value(index);
             Ok(Uuid::from_slice(value).unwrap().into()) // unwrap is safe: 
slice is always 16 bytes
         }
-        DataType::BinaryView => {
-            let array = typed_value.as_binary_view();
-            let value = array.value(index);
+        DataType::Binary | DataType::LargeBinary | DataType::BinaryView => {
+            let value = binary_array_value(typed_value.as_ref(), index);

Review Comment:
   Oh, this one is special. Unlike `value` and `metadata`, `typed_value` is 
_not_ always a binary-like type. So we couldn't rely on a hypothetical 
`BinaryLikeArray` trait for type safety.



##########
parquet-variant-compute/src/variant_array.rs:
##########
@@ -41,6 +41,40 @@ use parquet_variant::{
 use std::borrow::Cow;
 use std::sync::Arc;
 
+/// Returns the raw bytes at the given index from a binary-like array.
+///
+/// # Panics
+/// Panics if the array is not `Binary`, `LargeBinary`, or `BinaryView`,
+/// or if `index` is out of bounds.
+pub(crate) fn binary_array_value(array: &dyn Array, index: usize) -> &[u8] {
+    match array.data_type() {
+        DataType::Binary => array.as_binary::<i32>().value(index),
+        DataType::LargeBinary => array.as_binary::<i64>().value(index),
+        DataType::BinaryView => array.as_binary_view().value(index),
+        other => panic!("Expected Binary, LargeBinary, or BinaryView array, 
got {other}"),

Review Comment:
   I don't love panics... is there something that makes this one structurally 
impossible to trigger?



##########
parquet-variant-compute/src/variant_array.rs:
##########
@@ -41,6 +41,40 @@ use parquet_variant::{
 use std::borrow::Cow;
 use std::sync::Arc;
 
+/// Returns the raw bytes at the given index from a binary-like array.
+///
+/// # Panics
+/// Panics if the array is not `Binary`, `LargeBinary`, or `BinaryView`,
+/// or if `index` is out of bounds.
+pub(crate) fn binary_array_value(array: &dyn Array, index: usize) -> &[u8] {
+    match array.data_type() {
+        DataType::Binary => array.as_binary::<i32>().value(index),
+        DataType::LargeBinary => array.as_binary::<i64>().value(index),
+        DataType::BinaryView => array.as_binary_view().value(index),
+        other => panic!("Expected Binary, LargeBinary, or BinaryView array, 
got {other}"),

Review Comment:
   Instead of a panic, could we return `Option<&[u8]>` and let the caller deal 
with it?
   In many cases they could simply `.unwrap()` with a safety note about match 
arms etc guaranteeing safety?



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