@@ -19,9 +19,8 @@ use futures::TryStreamExt;
1919use futures:: future:: BoxFuture ;
2020use serde:: Serialize ;
2121use vortex:: array:: ArrayRef ;
22- use vortex:: array:: LEGACY_SESSION ;
2322use vortex:: array:: VortexSessionExecute ;
24- use vortex:: array:: arrow:: ArrowArrayExecutor ;
23+ use vortex:: array:: arrow:: ArrowSessionExt ;
2524use vortex:: array:: buffer:: BufferHandle ;
2625use vortex:: array:: dtype:: DType ;
2726use vortex:: array:: serde:: SerializedArray ;
@@ -312,8 +311,8 @@ impl VortexFileHandle {
312311 . await
313312 . map_err ( |e| JsValue :: from_str ( & e. to_string ( ) ) ) ?;
314313
315- let schema =
316- dtype_to_schema ( & dtype , "value" ) . map_err ( |e| JsValue :: from_str ( & e. to_string ( ) ) ) ?;
314+ let schema = dtype_to_schema ( & self . session , & dtype , "value" )
315+ . map_err ( |e| JsValue :: from_str ( & e. to_string ( ) ) ) ?;
317316 let arrow_schema = Arc :: new ( schema) ;
318317
319318 let mut buf = Vec :: new ( ) ;
@@ -322,7 +321,7 @@ impl VortexFileHandle {
322321 . map_err ( |e| JsValue :: from_str ( & e. to_string ( ) ) ) ?;
323322
324323 for chunk in chunks {
325- let batch = array_to_record_batch ( chunk, & dtype, & arrow_schema)
324+ let batch = array_to_record_batch ( & self . session , chunk, & dtype, & arrow_schema)
326325 . map_err ( |e| JsValue :: from_str ( & e. to_string ( ) ) ) ?;
327326 writer
328327 . write ( & batch)
@@ -511,11 +510,11 @@ impl VortexFileHandle {
511510
512511 // Convert to Arrow IPC.
513512 let array_dtype = current. dtype ( ) . clone ( ) ;
514- let schema = dtype_to_schema ( & array_dtype, "value" )
513+ let schema = dtype_to_schema ( & self . session , & array_dtype, "value" )
515514 . map_err ( |e| JsValue :: from_str ( & e. to_string ( ) ) ) ?;
516515 let arrow_schema = Arc :: new ( schema) ;
517516
518- let batch = array_to_record_batch ( current, & array_dtype, & arrow_schema)
517+ let batch = array_to_record_batch ( & self . session , current, & array_dtype, & arrow_schema)
519518 . map_err ( |e| JsValue :: from_str ( & e. to_string ( ) ) ) ?;
520519
521520 let mut ipc_buf = Vec :: new ( ) ;
@@ -743,14 +742,14 @@ fn downgrade_arrow_type(dt: DataType) -> DataType {
743742}
744743
745744/// Create an Arrow Schema from a Vortex DType, with view types downgraded.
746- fn dtype_to_schema ( dtype : & DType , default_name : & str ) -> VortexResult < Schema > {
745+ fn dtype_to_schema (
746+ session : & VortexSession ,
747+ dtype : & DType ,
748+ default_name : & str ,
749+ ) -> VortexResult < Schema > {
747750 let schema = match dtype {
748- DType :: Struct ( ..) => dtype. to_arrow_schema ( ) ?,
749- other => {
750- let arrow_dt = other. to_arrow_dtype ( ) ?;
751- let nullable = other. is_nullable ( ) ;
752- Schema :: new ( vec ! [ Field :: new( default_name, arrow_dt, nullable) ] )
753- }
751+ DType :: Struct ( ..) => session. arrow ( ) . to_arrow_schema ( dtype) ?,
752+ other => Schema :: new ( vec ! [ session. arrow( ) . to_arrow_field( default_name, other) ?] ) ,
754753 } ;
755754 // Downgrade view types in all fields.
756755 Ok ( Schema :: new (
@@ -770,8 +769,9 @@ fn dtype_to_schema(dtype: &DType, default_name: &str) -> VortexResult<Schema> {
770769
771770/// Convert a Vortex ArrayRef into an Arrow RecordBatch using the given schema.
772771///
773- /// Always uses `execute_arrow` with explicit types to ensure view types are avoided.
772+ /// Always executes against an explicit target type to ensure view types are avoided.
774773fn array_to_record_batch (
774+ session : & VortexSession ,
775775 array : ArrayRef ,
776776 dtype : & DType ,
777777 schema : & Arc < Schema > ,
@@ -780,8 +780,11 @@ fn array_to_record_batch(
780780 DType :: Struct ( ..) => DataType :: Struct ( schema. fields ( ) . clone ( ) ) ,
781781 _ => schema. field ( 0 ) . data_type ( ) . clone ( ) ,
782782 } ;
783- let mut ctx = LEGACY_SESSION . create_execution_ctx ( ) ;
784- let arrow = array. execute_arrow ( Some ( & data_type) , & mut ctx) ?;
783+ let target = Field :: new ( "" , data_type, array. dtype ( ) . is_nullable ( ) ) ;
784+ let mut ctx = session. create_execution_ctx ( ) ;
785+ let arrow = session
786+ . arrow ( )
787+ . execute_arrow ( array, Some ( & target) , & mut ctx) ?;
785788 match dtype {
786789 DType :: Struct ( ..) => Ok ( RecordBatch :: from ( arrow. as_struct ( ) . clone ( ) ) ) ,
787790 _ => Ok ( RecordBatch :: try_new ( schema. clone ( ) , vec ! [ arrow] ) ?) ,
0 commit comments