etseidl commented on code in PR #12088:
URL: https://github.com/apache/arrow-rs/pull/12088#discussion_r4484187856


##########
arrow-array/src/array/mod.rs:
##########
@@ -432,6 +432,18 @@ pub unsafe trait Array: std::fmt::Debug + Send + Sync {
 /// A reference-counted reference to a generic `Array`
 pub type ArrayRef = Arc<dyn Array>;
 
+/// Returns `true` if two child value arrays have the same layout and backing 
buffers.
+///
+/// This is useful for recognizing shared values in [`DictionaryArray`] and 
[`RunArray`].
+/// It first checks whether the [`ArrayRef`]s point to the same allocation, 
then falls back
+/// to [`ArrayData::ptr_eq`] to recognize shallow clones such as 
`Arc::new(array.clone())`.
+///
+/// This checks storage identity, not logical equality: arrays with equal 
values but
+/// different buffers return `false`.
+pub fn child_values_ptr_eq(left: &ArrayRef, right: &ArrayRef) -> bool {
+    Arc::ptr_eq(left, right) || left.to_data().ptr_eq(&right.to_data())

Review Comment:
   IIUC `to_data` will eventually clone. Does this have any impact on #11743?



##########
arrow-array/src/array/mod.rs:
##########
@@ -1093,9 +1105,34 @@ mod tests {
     use super::*;
     use crate::cast::{as_union_array, downcast_array};
     use crate::downcast_run_array;
+    use crate::types::Int8Type;
     use arrow_buffer::MutableBuffer;
     use arrow_schema::{Field, Fields, UnionFields, UnionMode};
 
+    #[test]
+    fn test_child_values_ptr_eq_same_arc() {
+        let dictionary = DictionaryArray::<Int8Type>::new(
+            Int8Array::from(vec![0, 1]),
+            Arc::new(StringArray::from(vec!["a", "b"])),
+        );
+        let values = Arc::clone(dictionary.values());
+
+        assert!(Arc::ptr_eq(dictionary.values(), &values));
+        assert!(child_values_ptr_eq(dictionary.values(), &values));
+    }
+
+    #[test]
+    fn test_child_values_ptr_eq_shared_buffers() {

Review Comment:
   Would be nice to add some negative tests. GPT noted:
   
   > The two new tests cover only successful dictionary/StringArray 
comparisons. The important contract also needs coverage for arrays that share 
storage but cannot reuse the same values-index mapping.
   >
   > I ran independent probes covering:
   > - Equal values in independently allocated buffers.
   > - Different slices and lengths over shared storage.
   > - Different validity bitmaps and type metadata.
   > - Different nested children and StringView payload buffers.
   > - Shared REE values with different run boundaries.



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