alamb commented on code in PR #5796:
URL: https://github.com/apache/arrow-rs/pull/5796#discussion_r1618788242
##########
arrow-array/src/builder/generic_bytes_view_builder.rs:
##########
@@ -219,3 +327,74 @@ pub type StringViewBuilder =
GenericByteViewBuilder<StringViewType>;
/// Values can be appended using [`GenericByteViewBuilder::append_value`], and
nulls with
/// [`GenericByteViewBuilder::append_null`] as normal.
pub type BinaryViewBuilder = GenericByteViewBuilder<BinaryViewType>;
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::Array;
+
+ #[test]
+ fn test_string_view() {
+ let b1 = Buffer::from(b"world\xFFbananas\xF0\x9F\x98\x81");
+ let b2 = Buffer::from(b"cupcakes");
+ let b3 = Buffer::from(b"Many strings are here contained of great
length and verbosity");
+
+ let mut v = StringViewBuilder::new();
+ assert_eq!(v.append_block(b1), 0);
+
+ v.append_value("This is a very long string that exceeds the inline
length");
Review Comment:
These values are appended to the current block (`0`) right?
##########
arrow-array/src/builder/generic_bytes_view_builder.rs:
##########
@@ -219,3 +327,74 @@ pub type StringViewBuilder =
GenericByteViewBuilder<StringViewType>;
/// Values can be appended using [`GenericByteViewBuilder::append_value`], and
nulls with
/// [`GenericByteViewBuilder::append_null`] as normal.
pub type BinaryViewBuilder = GenericByteViewBuilder<BinaryViewType>;
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::Array;
+
+ #[test]
+ fn test_string_view() {
+ let b1 = Buffer::from(b"world\xFFbananas\xF0\x9F\x98\x81");
+ let b2 = Buffer::from(b"cupcakes");
+ let b3 = Buffer::from(b"Many strings are here contained of great
length and verbosity");
+
+ let mut v = StringViewBuilder::new();
+ assert_eq!(v.append_block(b1), 0);
+
+ v.append_value("This is a very long string that exceeds the inline
length");
+ v.append_value("This is another very long string that exceeds the
inline length");
+
+ assert_eq!(v.append_block(b2), 2);
+ assert_eq!(v.append_block(b3), 3);
+
+ // Test short strings
+ v.try_append_view(0, 0, 5).unwrap(); // world
+ v.try_append_view(0, 6, 7).unwrap(); // bananas
+ v.try_append_view(2, 3, 5).unwrap(); // cake
+ v.try_append_view(2, 0, 3).unwrap(); // cup
+ v.try_append_view(2, 0, 8).unwrap(); // cupcakes
+ v.try_append_view(0, 13, 4).unwrap(); // 😁
+
+ // Test longer strings
+ v.try_append_view(3, 0, 16).unwrap(); // Many strings are
+ v.try_append_view(1, 0, 19).unwrap(); // This is a very long
+ v.try_append_view(3, 13, 27).unwrap(); // here contained of great
length
+
+ v.append_value("I do so like long strings");
+
+ let array = v.finish_cloned();
+ array.to_data().validate_full().unwrap();
+ assert_eq!(array.data_buffers().len(), 5);
+ let actual: Vec<_> = array.iter().map(Option::unwrap).collect();
+ assert_eq!(
+ actual,
+ &[
+ "This is a very long string that exceeds the inline length",
+ "This is another very long string that exceeds the inline
length",
+ "world",
+ "bananas",
+ "cakes",
+ "cup",
+ "cupcakes",
+ "😁",
+ "Many strings are",
+ "This is a very long",
+ "are here contained of great",
+ "I do so like long strings"
+ ]
+ );
+
+ let err = v.try_append_view(0, u32::MAX, 1).unwrap_err();
Review Comment:
Can you please also add an error test for an invalid block ID? (aka "No
block found with index {block}")
--
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]