@@ -5,20 +5,15 @@ use std::cmp::max;
55use std:: ops:: Range ;
66
77use vortex_array:: ArrayRef ;
8- use vortex_array:: ExecutionCtx ;
98use vortex_array:: IntoArray ;
10- use vortex_array:: arrays:: SliceKernel ;
9+ use vortex_array:: arrays:: SliceReduce ;
1110use vortex_error:: VortexResult ;
1211
1312use crate :: BitPackedArray ;
1413use crate :: BitPackedVTable ;
1514
16- impl SliceKernel for BitPackedVTable {
17- fn slice (
18- array : & BitPackedArray ,
19- range : Range < usize > ,
20- _ctx : & mut ExecutionCtx ,
21- ) -> VortexResult < Option < ArrayRef > > {
15+ impl SliceReduce for BitPackedVTable {
16+ fn slice ( array : & BitPackedArray , range : Range < usize > ) -> VortexResult < Option < ArrayRef > > {
2217 let offset_start = range. start + array. offset ( ) as usize ;
2318 let offset_stop = range. end + array. offset ( ) as usize ;
2419 let offset = offset_start % 1024 ;
@@ -51,43 +46,44 @@ impl SliceKernel for BitPackedVTable {
5146
5247#[ cfg( test) ]
5348mod tests {
54- use std:: sync:: LazyLock ;
55-
5649 use vortex_array:: Array ;
57- use vortex_array:: IntoArray ;
58- use vortex_array:: VortexSessionExecute ;
59- use vortex_array:: arrays:: SliceArray ;
60- use vortex_array:: session:: ArraySession ;
61- use vortex_array:: vtable:: VTable ;
50+ use vortex_array:: arrays:: SliceReduce ;
51+ use vortex_array:: arrays:: SliceVTable ;
6252 use vortex_error:: VortexResult ;
63- use vortex_session:: VortexSession ;
6453
6554 use crate :: BitPackedVTable ;
6655 use crate :: bitpack_compress:: bitpack_encode;
6756
68- static SESSION : LazyLock < VortexSession > =
69- LazyLock :: new ( || VortexSession :: empty ( ) . with :: < ArraySession > ( ) ) ;
57+ #[ test]
58+ fn test_slice_returns_bitpacked ( ) -> VortexResult < ( ) > {
59+ let values = vortex_array:: arrays:: PrimitiveArray :: from_iter ( 0u32 ..2048 ) ;
60+ let bitpacked = bitpack_encode ( & values, 11 , None ) ?;
61+
62+ let result =
63+ BitPackedVTable :: slice ( & bitpacked, 500 ..1500 ) ?. expect ( "expected slice to succeed" ) ;
64+
65+ assert ! ( result. is:: <BitPackedVTable >( ) ) ;
66+ let result_bp = result. as_ :: < BitPackedVTable > ( ) ;
67+ assert_eq ! ( result_bp. offset( ) , 500 ) ;
68+ assert_eq ! ( result. len( ) , 1000 ) ;
69+
70+ Ok ( ( ) )
71+ }
7072
7173 #[ test]
72- fn test_execute_parent_returns_bitpacked_slice ( ) -> VortexResult < ( ) > {
74+ fn test_slice_via_array_trait ( ) -> VortexResult < ( ) > {
7375 let values = vortex_array:: arrays:: PrimitiveArray :: from_iter ( 0u32 ..2048 ) ;
7476 let bitpacked = bitpack_encode ( & values, 11 , None ) ?;
7577
76- let slice_array = SliceArray :: new ( bitpacked. clone ( ) . into_array ( ) , 500 ..1500 ) ;
77-
78- let mut ctx = SESSION . create_execution_ctx ( ) ;
79- let reduced = <BitPackedVTable as VTable >:: execute_parent (
80- & bitpacked,
81- & slice_array. into_array ( ) ,
82- 0 ,
83- & mut ctx,
84- ) ?
85- . expect ( "expected slice kernel to execute" ) ;
86-
87- assert ! ( reduced. is:: <BitPackedVTable >( ) ) ;
88- let reduced_bp = reduced. as_ :: < BitPackedVTable > ( ) ;
89- assert_eq ! ( reduced_bp. offset( ) , 500 ) ;
90- assert_eq ! ( reduced. len( ) , 1000 ) ;
78+ let sliced = bitpacked. as_ref ( ) . slice ( 500 ..1500 ) ?;
79+
80+ // After optimize, the SliceArray should have been reduced away.
81+ assert ! (
82+ !sliced. is:: <SliceVTable >( ) ,
83+ "expected SliceReduce to eliminate the SliceArray wrapper"
84+ ) ;
85+ assert ! ( sliced. is:: <BitPackedVTable >( ) ) ;
86+ assert_eq ! ( sliced. len( ) , 1000 ) ;
9187
9288 Ok ( ( ) )
9389 }
0 commit comments