mbutrovich commented on code in PR #11625:
URL: https://github.com/apache/arrow-rs/pull/11625#discussion_r4299043648


##########
arrow-select/src/zip.rs:
##########
@@ -1748,4 +1750,83 @@ mod test {
         ]);
         assert_eq!(actual, &expected);
     }
+
+    #[test]
+    fn test_zip_kernel_scalar_strings_array_view_sliced_inline() {
+        // Both scalars are inlined, but each slice keeps its array's data 
buffer
+        let truthy =
+            StringViewArray::from(vec!["x", "a string longer than twelve 
bytes"]).slice(0, 1);
+        let falsy =
+            StringViewArray::from(vec!["hello", "another string longer than 
twelve"]).slice(0, 1);
+
+        let mask = BooleanArray::from(vec![true, false, true, false]);
+        let out = zip(&mask, &Scalar::new(&truthy), 
&Scalar::new(&falsy)).unwrap();
+        out.to_data().validate_full().unwrap();
+        let actual = out.as_string_view();
+        let expected = StringViewArray::from(vec!["x", "hello", "x", "hello"]);
+        assert_eq!(actual, &expected);
+    }
+
+    #[test]
+    fn test_zip_kernel_scalar_binary_array_view_sliced_inline_short() {
+        // A falsy value of at most 4 bytes keeps zero padding in view bytes 8 
to 11
+        let truthy = BinaryViewArray::from_iter_values([
+            b"x".as_slice(),
+            b"a value longer than twelve bytes",
+        ])
+        .slice(0, 1);
+        let falsy = BinaryViewArray::from_iter_values([
+            b"ab".as_slice(),
+            b"another value longer than twelve",
+        ])
+        .slice(0, 1);
+
+        let mask = BooleanArray::from(vec![false, true, false]);
+        let out = zip(&mask, &Scalar::new(&truthy), 
&Scalar::new(&falsy)).unwrap();
+        out.to_data().validate_full().unwrap();
+        let actual = out.as_binary_view();
+        let expected = BinaryViewArray::from_iter_values([b"ab".as_slice(), 
b"x", b"ab"]);
+        assert_eq!(actual, &expected);
+    }
+
+    #[test]
+    fn test_zip_kernel_scalar_strings_array_view_sliced_long_falsy() {
+        // A long falsy value must still be remapped after the truthy buffers
+        let truthy =
+            StringViewArray::from(vec!["a string longer than twelve bytes", 
"x"]).slice(0, 1);
+        let falsy =
+            StringViewArray::from(vec!["y", "another string longer than 
twelve"]).slice(1, 1);
+
+        let mask = BooleanArray::from(vec![true, false]);
+        let out = zip(&mask, &Scalar::new(&truthy), 
&Scalar::new(&falsy)).unwrap();
+        out.to_data().validate_full().unwrap();
+        let actual = out.as_string_view();
+        let expected = StringViewArray::from(vec![
+            "a string longer than twelve bytes",
+            "another string longer than twelve",
+        ]);

Review Comment:
   What do you think about making the long falsy value exactly 13 bytes? That 
puts it one byte past the inline limit, so the test also checks the boundary 
from the other side. With the 33 byte value, changing the check to `<= 
MAX_INLINE_VIEW_LEN + 1` still passes all 46 `zip::` tests. With a 13 byte 
value, this test fails on that change because the unmodified view points into 
the truthy buffer.
   
   ```suggestion
           // A 13 byte falsy value is not inlined, so it must be remapped 
after the truthy buffers
           let truthy =
               StringViewArray::from(vec!["a string longer than twelve bytes", 
"x"]).slice(0, 1);
           let falsy = StringViewArray::from(vec!["y", "thirteen 
byte"]).slice(1, 1);
   
           let mask = BooleanArray::from(vec![true, false]);
           let out = zip(&mask, &Scalar::new(&truthy), 
&Scalar::new(&falsy)).unwrap();
           out.to_data().validate_full().unwrap();
           let actual = out.as_string_view();
           let expected =
               StringViewArray::from(vec!["a string longer than twelve bytes", 
"thirteen byte"]);
   ```



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