MCPcopy Create free account
hub / github.com/apache/arrow-rs / test_run_array_unslice

Function test_run_array_unslice

arrow-ipc/src/writer.rs:3053–3104  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3051
3052 #[test]
3053 fn test_run_array_unslice() {
3054 let total_len = 80;
3055 let vals: Vec<Option<i32>> = vec![Some(1), None, Some(2), Some(3), Some(4), None, Some(5)];
3056 let repeats: Vec<usize> = vec![3, 4, 1, 2];
3057 let mut input_array: Vec<Option<i32>> = Vec::with_capacity(total_len);
3058 for ix in 0_usize..32 {
3059 let repeat: usize = repeats[ix % repeats.len()];
3060 let val: Option<i32> = vals[ix % vals.len()];
3061 input_array.resize(input_array.len() + repeat, val);
3062 }
3063
3064 // Encode the input_array to run array
3065 let mut builder =
3066 PrimitiveRunBuilder::<Int16Type, Int32Type>::with_capacity(input_array.len());
3067 builder.extend(input_array.iter().copied());
3068 let run_array = builder.finish();
3069
3070 // test for all slice lengths.
3071 for slice_len in 1..=total_len {
3072 // test for offset = 0, slice length = slice_len
3073 let sliced_run_array: RunArray<Int16Type> =
3074 run_array.slice(0, slice_len).into_data().into();
3075
3076 // Create unsliced run array.
3077 let unsliced_run_array = into_zero_offset_run_array(sliced_run_array).unwrap();
3078 let typed = unsliced_run_array
3079 .downcast::<PrimitiveArray<Int32Type>>()
3080 .unwrap();
3081 let expected: Vec<Option<i32>> = input_array.iter().take(slice_len).copied().collect();
3082 let actual: Vec<Option<i32>> = typed.into_iter().collect();
3083 assert_eq!(expected, actual);
3084
3085 // test for offset = total_len - slice_len, length = slice_len
3086 let sliced_run_array: RunArray<Int16Type> = run_array
3087 .slice(total_len - slice_len, slice_len)
3088 .into_data()
3089 .into();
3090
3091 // Create unsliced run array.
3092 let unsliced_run_array = into_zero_offset_run_array(sliced_run_array).unwrap();
3093 let typed = unsliced_run_array
3094 .downcast::<PrimitiveArray<Int32Type>>()
3095 .unwrap();
3096 let expected: Vec<Option<i32>> = input_array
3097 .iter()
3098 .skip(total_len - slice_len)
3099 .copied()
3100 .collect();
3101 let actual: Vec<Option<i32>> = typed.into_iter().collect();
3102 assert_eq!(expected, actual);
3103 }
3104 }
3105
3106 fn generate_list_data<O: OffsetSizeTrait>() -> GenericListArray<O> {
3107 let mut ls = GenericListBuilder::<O, _>::new(UInt32Builder::new());

Callers

nothing calls this directly

Calls 12

collectMethod · 0.80
lenMethod · 0.45
resizeMethod · 0.45
extendMethod · 0.45
iterMethod · 0.45
finishMethod · 0.45
into_dataMethod · 0.45
sliceMethod · 0.45
takeMethod · 0.45
into_iterMethod · 0.45
skipMethod · 0.45

Tested by

no test coverage detected