@@ -150,7 +150,11 @@ mod tests {
150150 use vortex:: array:: validity:: Validity ;
151151 use vortex:: buffer:: Buffer ;
152152 use vortex:: buffer:: buffer;
153+ use vortex:: dtype:: DType ;
154+ use vortex:: dtype:: PType ;
155+ use vortex:: encodings:: runend:: RunEnd ;
153156 use vortex:: error:: VortexExpect ;
157+ use vortex:: error:: VortexResult ;
154158
155159 use super :: * ;
156160 use crate :: SESSION ;
@@ -160,13 +164,12 @@ mod tests {
160164
161165 #[ test]
162166 fn test_export_empty_list ( ) {
163- let list = unsafe {
164- ListArray :: new_unchecked (
165- Buffer :: < u32 > :: empty ( ) . into_array ( ) ,
166- Buffer :: < u32 > :: empty ( ) . into_array ( ) ,
167- Validity :: AllValid ,
168- )
169- }
167+ let list = ListArray :: try_new (
168+ Buffer :: < u32 > :: empty ( ) . into_array ( ) ,
169+ buffer ! [ 0u32 ] . into_array ( ) ,
170+ Validity :: AllValid ,
171+ )
172+ . vortex_expect ( "list creation should succeed" )
170173 . into_array ( ) ;
171174
172175 let list_type = LogicalType :: list_type ( LogicalType :: uint32 ( ) )
@@ -189,20 +192,91 @@ mod tests {
189192 }
190193
191194 #[ test]
192- fn test_export_non_empty_list_of_strings ( ) {
193- let list = unsafe {
194- ListArray :: new_unchecked (
195- <VarBinArray as FromIterator < _ > >:: from_iter ( [
196- Some ( "abc" ) ,
197- Some ( "def" ) ,
198- None ,
199- Some ( "ghi" ) ,
200- ] )
201- . into_array ( ) ,
202- buffer ! [ 0u8 , 1 , 2 , 3 , 4 ] . into_array ( ) ,
203- Validity :: from_iter ( [ true , true , false , true ] ) ,
195+ fn test_export_u64_list ( ) {
196+ let list = ListArray :: try_new (
197+ buffer ! [ 1u64 , 2 , 3 , 4 , 5 ] . into_array ( ) ,
198+ buffer ! [ 0u8 , 1 , 2 , 3 , 4 , 5 ] . into_array ( ) ,
199+ Validity :: AllValid ,
200+ )
201+ . vortex_expect ( "list creation should succeed" )
202+ . into_array ( ) ;
203+ assert_eq ! (
204+ list. dtype( ) ,
205+ & DType :: List (
206+ Arc :: new( DType :: Primitive ( PType :: U64 , false . into( ) ) ) ,
207+ true . into( )
204208 )
205- }
209+ ) ;
210+
211+ let list_type = LogicalType :: list_type ( LogicalType :: uint64 ( ) )
212+ . vortex_expect ( "LogicalTypeRef creation should succeed for test data" ) ;
213+ let mut chunk = DataChunk :: new ( [ list_type] ) ;
214+
215+ let mut ctx = SESSION . create_execution_ctx ( ) ;
216+ new_array_exporter ( list, & ConversionCache :: default ( ) , & mut ctx)
217+ . unwrap ( )
218+ . export ( 0 , 5 , chunk. get_vector_mut ( 0 ) , & mut ctx)
219+ . unwrap ( ) ;
220+ chunk. set_len ( 5 ) ;
221+
222+ assert_eq ! (
223+ format!( "{}" , String :: try_from( & * chunk) . unwrap( ) ) ,
224+ r#"Chunk - [1 Columns]
225+ - FLAT UBIGINT[]: 5 = [ [1], [2], [3], [4], [5]]
226+ "#
227+ ) ;
228+ }
229+
230+ // Ensure runend-compressed list is properly flattened
231+ #[ test]
232+ fn test_export_list_with_runend_elements ( ) -> VortexResult < ( ) > {
233+ let mut ctx = SESSION . create_execution_ctx ( ) ;
234+ let elements = RunEnd :: encode ( buffer ! [ 100u32 , 100 , 200 , 200 , 200 ] . into_array ( ) , & mut ctx) ?;
235+
236+ let list = ListArray :: try_new (
237+ elements. into_array ( ) ,
238+ buffer ! [ 0u32 , 2 , 5 ] . into_array ( ) ,
239+ Validity :: AllValid ,
240+ )
241+ . vortex_expect ( "list creation should succeed" )
242+ . into_array ( ) ;
243+
244+ let list_type = LogicalType :: list_type ( LogicalType :: uint32 ( ) )
245+ . vortex_expect ( "LogicalTypeRef creation should succeed for test data" ) ;
246+ let mut chunk = DataChunk :: new ( [ list_type] ) ;
247+
248+ new_array_exporter ( list, & ConversionCache :: default ( ) , & mut ctx) ?. export (
249+ 0 ,
250+ 2 ,
251+ chunk. get_vector_mut ( 0 ) ,
252+ & mut ctx,
253+ ) ?;
254+ chunk. set_len ( 2 ) ;
255+
256+ assert_eq ! (
257+ format!( "{}" , String :: try_from( & * chunk) ?) ,
258+ r#"Chunk - [1 Columns]
259+ - FLAT UINTEGER[]: 2 = [ [100, 100], [200, 200, 200]]
260+ "#
261+ ) ;
262+
263+ Ok ( ( ) )
264+ }
265+
266+ #[ test]
267+ fn test_export_non_empty_list_of_strings ( ) {
268+ let list = ListArray :: try_new (
269+ <VarBinArray as FromIterator < _ > >:: from_iter ( [
270+ Some ( "abc" ) ,
271+ Some ( "def" ) ,
272+ None ,
273+ Some ( "ghi" ) ,
274+ ] )
275+ . into_array ( ) ,
276+ buffer ! [ 0u8 , 1 , 2 , 3 , 4 ] . into_array ( ) ,
277+ Validity :: from_iter ( [ true , true , false , true ] ) ,
278+ )
279+ . vortex_expect ( "list creation should succeed" )
206280 . into_array ( ) ;
207281
208282 let list_type = LogicalType :: list_type ( LogicalType :: varchar ( ) )
0 commit comments