@@ -5,18 +5,21 @@ use std::sync::Arc;
55
66use async_trait:: async_trait;
77use futures:: future:: try_join_all;
8+ use vortex:: array:: ArrayRef ;
89use vortex:: array:: Canonical ;
910use vortex:: array:: IntoArray ;
1011use vortex:: array:: VortexSessionExecute ;
1112use vortex:: array:: arrays:: BoolArray ;
1213use vortex:: array:: arrays:: DecimalArray ;
1314use vortex:: array:: arrays:: ExtensionArray ;
15+ use vortex:: array:: arrays:: ListViewArray ;
1416use vortex:: array:: arrays:: PrimitiveArray ;
1517use vortex:: array:: arrays:: StructArray ;
1618use vortex:: array:: arrays:: VarBinViewArray ;
1719use vortex:: array:: arrays:: bool:: BoolDataParts ;
1820use vortex:: array:: arrays:: decimal:: DecimalDataParts ;
1921use vortex:: array:: arrays:: extension:: ExtensionArrayExt ;
22+ use vortex:: array:: arrays:: listview:: ListViewDataParts ;
2023use vortex:: array:: arrays:: primitive:: PrimitiveDataParts ;
2124use vortex:: array:: arrays:: struct_:: StructDataParts ;
2225use vortex:: array:: arrays:: varbinview:: BinaryView ;
@@ -29,6 +32,19 @@ use vortex::buffer::Buffer;
2932use vortex:: buffer:: ByteBuffer ;
3033use vortex:: error:: VortexResult ;
3134
35+ /// Copy a canonical child array to the host.
36+ async fn child_into_host ( child : ArrayRef ) -> VortexResult < ArrayRef > {
37+ #[ expect(
38+ clippy:: disallowed_methods,
39+ reason = "CanonicalCudaExt threads no session through"
40+ ) ]
41+ Ok ( child
42+ . execute :: < Canonical > ( & mut legacy_session ( ) . create_execution_ctx ( ) ) ?
43+ . into_host ( )
44+ . await ?
45+ . into_array ( ) )
46+ }
47+
3248/// Move all canonical data from to_host from device.
3349#[ async_trait]
3450pub trait CanonicalCudaExt {
@@ -102,18 +118,15 @@ impl CanonicalCudaExt for Canonical {
102118 n @ Canonical :: Null ( _) => Ok ( n) ,
103119 Canonical :: Bool ( bool) => {
104120 let len = bool. len ( ) ;
105- let validity = bool. validity ( ) ?;
121+ let validity = validity_into_host ( bool. validity ( ) ? ) . await ?;
106122 let BoolDataParts { bits, meta } = bool. into_data ( ) . into_parts ( len) ;
107123
108124 let bits = BitBuffer :: new_with_offset (
109125 bits. try_into_host ( ) ?. await ?,
110126 meta. len ( ) ,
111127 meta. offset ( ) ,
112128 ) ;
113- Ok ( Canonical :: Bool ( BoolArray :: new (
114- bits,
115- validity_into_host ( validity) . await ?,
116- ) ) )
129+ Ok ( Canonical :: Bool ( BoolArray :: new ( bits, validity) ) )
117130 }
118131 Canonical :: Primitive ( prim) => {
119132 let PrimitiveDataParts {
@@ -153,6 +166,7 @@ impl CanonicalCudaExt for Canonical {
153166 validity,
154167 dtype,
155168 } = varbinview. into_data_parts ( ) ;
169+ let validity = validity_into_host ( validity) . await ?;
156170
157171 // Copy all device views to host
158172 let host_views = views. try_into_host ( ) ?. await ?;
@@ -167,11 +181,27 @@ impl CanonicalCudaExt for Canonical {
167181 let host_buffers = try_join_all ( host_buffers) . await ?;
168182 let host_buffers: Arc < [ ByteBuffer ] > = Arc :: from ( host_buffers) ;
169183
170- let validity = validity_into_host ( validity) . await ?;
171184 Ok ( Canonical :: VarBinView ( unsafe {
172185 VarBinViewArray :: new_unchecked ( host_views, host_buffers, dtype, validity)
173186 } ) )
174187 }
188+ Canonical :: List ( list) => {
189+ let ListViewDataParts {
190+ elements,
191+ offsets,
192+ sizes,
193+ validity,
194+ ..
195+ } = list. into_data_parts ( ) ;
196+ let validity = validity_into_host ( validity) . await ?;
197+
198+ Ok ( Canonical :: List ( ListViewArray :: try_new (
199+ child_into_host ( elements) . await ?,
200+ child_into_host ( offsets) . await ?,
201+ child_into_host ( sizes) . await ?,
202+ validity,
203+ ) ?) )
204+ }
175205 Canonical :: Extension ( ext) => {
176206 // Copy the storage array to host and rewrap in ExtensionArray.
177207 #[ expect(
0 commit comments