rich-t-kid-datadog commented on code in PR #7713:
URL: https://github.com/apache/arrow-rs/pull/7713#discussion_r2182891831
##########
arrow-cast/src/cast/mod.rs:
##########
@@ -10684,4 +10716,350 @@ mod tests {
)) as ArrayRef;
assert_eq!(*fixed_array, *r);
}
+ #[cfg(test)]
+ mod run_end_encoded_tests {
+ use super::*;
+ use arrow_schema::{DataType, Field};
+ use std::sync::Arc;
+
+ /// Test casting FROM RunEndEncoded to primitive types
+ #[test]
+ fn test_run_end_encoded_to_primitive() {
+ // Create a RunEndEncoded array: [1, 1, 2, 2, 2, 3]
+ let run_ends = Int32Array::from(vec![2, 5, 6]);
+ let values = Int32Array::from(vec![1, 2, 3]);
+ let run_array = RunArray::<Int32Type>::try_new(&run_ends,
&values).unwrap();
+ let array_ref = Arc::new(run_array) as ArrayRef;
+ // Cast to Int64
+ let cast_result = cast(&array_ref, &DataType::Int64).unwrap();
+ // Verify the result is a RunArray with Int64 values
+ let result_run_array =
cast_result.as_any().downcast_ref::<Int64Array>().unwrap();
+ assert_eq!(
+ result_run_array.values(),
+ &[1i64, 1i64, 2i64, 2i64, 2i64, 3i64]
+ );
+ }
+
+ /// Test casting FROM RunEndEncoded to string
+ #[test]
+ fn test_run_end_encoded_to_string() {
+ // Create a RunEndEncoded array with Int32 values: [10, 10, 20,
30, 30]
+ let run_ends = Int32Array::from(vec![2, 3, 5]);
+ let values = Int32Array::from(vec![10, 20, 30]);
+ let run_array = RunArray::<Int32Type>::try_new(&run_ends,
&values).unwrap();
+ let array_ref = Arc::new(run_array) as ArrayRef;
+
+ // Cast to String
+ let cast_result = cast(&array_ref, &DataType::Utf8).unwrap();
+
+ // Verify the result is a RunArray with String values
+ let result_array =
cast_result.as_any().downcast_ref::<StringArray>().unwrap();
+ // Check that values are correct
+ assert_eq!(result_array.value(0), "10");
+ assert_eq!(result_array.value(1), "10");
+ assert_eq!(result_array.value(2), "20");
+ }
+
+ /// Test casting TO RunEndEncoded from primitive types
+ #[test]
+ fn test_primitive_to_run_end_encoded() {
+ // Create an Int32 array with repeated values: [1, 1, 2, 2, 2, 3]
+ let source_array = Int32Array::from(vec![1, 1, 2, 2, 2, 3]);
Review Comment:
Added two test the test for several consecutive Null values
--
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]