@@ -18,7 +18,7 @@ use pyo3::{
18
18
} ;
19
19
20
20
use re_arrow_util:: ArrowArrayDowncastRef as _;
21
- use re_chunk:: { Chunk , ChunkError , ChunkId , PendingRow , RowId , TimeColumn , TransportChunk } ;
21
+ use re_chunk:: { Chunk , ChunkError , ChunkId , PendingRow , RowId , TimeColumn , TimelineName } ;
22
22
use re_log_types:: TimePoint ;
23
23
use re_sdk:: { external:: nohash_hasher:: IntMap , ComponentDescriptor , EntityPath , Timeline } ;
24
24
@@ -54,23 +54,9 @@ pub fn descriptor_to_rust(component_descr: &Bound<'_, PyAny>) -> PyResult<Compon
54
54
/// Perform conversion between a pyarrow array to arrow types.
55
55
///
56
56
/// `name` is the name of the Rerun component, and the name of the pyarrow `Field` (column name).
57
- pub fn array_to_rust (
58
- arrow_array : & Bound < ' _ , PyAny > ,
59
- component_descr : & ComponentDescriptor ,
60
- ) -> PyResult < ( ArrowArrayRef , ArrowField ) > {
57
+ pub fn array_to_rust ( arrow_array : & Bound < ' _ , PyAny > ) -> PyResult < ArrowArrayRef > {
61
58
let py_array: PyArrowType < ArrowArrayData > = arrow_array. extract ( ) ?;
62
- let array = make_array ( py_array. 0 ) ;
63
-
64
- let datatype = array. data_type ( ) ;
65
- let metadata = TransportChunk :: field_metadata_component_descriptor ( component_descr) ;
66
- let field = ArrowField :: new (
67
- component_descr. component_name . to_string ( ) ,
68
- datatype. clone ( ) ,
69
- true ,
70
- )
71
- . with_metadata ( metadata) ;
72
-
73
- Ok ( ( array, field) )
59
+ Ok ( make_array ( py_array. 0 ) )
74
60
}
75
61
76
62
/// Build a [`PendingRow`] given a '**kwargs'-style dictionary of component arrays.
@@ -85,8 +71,7 @@ pub fn build_row_from_components(
85
71
let mut components = IntMap :: default ( ) ;
86
72
for ( component_descr, array) in components_per_descr {
87
73
let component_descr = descriptor_to_rust ( & component_descr) ?;
88
- let ( list_array, _field) = array_to_rust ( & array, & component_descr) ?;
89
-
74
+ let list_array = array_to_rust ( & array) ?;
90
75
components. insert ( component_descr, list_array) ;
91
76
}
92
77
@@ -107,36 +92,36 @@ pub fn build_chunk_from_components(
107
92
let chunk_id = ChunkId :: new ( ) ;
108
93
109
94
// Extract the timeline data
110
- let ( arrays, fields) : ( Vec < ArrowArrayRef > , Vec < ArrowField > ) = itertools:: process_results (
111
- timelines. iter ( ) . map ( |( name, array) | {
112
- let py_name = name. downcast :: < PyString > ( ) ?;
113
- let name: std:: borrow:: Cow < ' _ , str > = py_name. extract ( ) ?;
114
- array_to_rust ( & array, & ComponentDescriptor :: new ( name. to_string ( ) ) )
115
- } ) ,
116
- |iter| iter. unzip ( ) ,
117
- ) ?;
95
+ let ( arrays, timeline_names) : ( Vec < ArrowArrayRef > , Vec < TimelineName > ) =
96
+ itertools:: process_results (
97
+ timelines. iter ( ) . map ( |( name, array) | {
98
+ let py_name = name. downcast :: < PyString > ( ) ?;
99
+ let name: std:: borrow:: Cow < ' _ , str > = py_name. extract ( ) ?;
100
+ let timeline_name: TimelineName = name. as_ref ( ) . into ( ) ;
101
+ array_to_rust ( & array) . map ( |array| ( array, timeline_name) )
102
+ } ) ,
103
+ |iter| iter. unzip ( ) ,
104
+ ) ?;
118
105
119
106
let timelines: Result < Vec < _ > , ChunkError > = arrays
120
107
. into_iter ( )
121
- . zip ( fields)
122
- . map ( |( array, field) | {
123
- let timeline_data =
124
- TimeColumn :: read_array ( & ArrowArrayRef :: from ( array) ) . map_err ( |err| {
125
- ChunkError :: Malformed {
126
- reason : format ! ( "Invalid timeline {}: {err}" , field. name( ) ) ,
127
- }
128
- } ) ?;
129
- let timeline = match field. data_type ( ) {
130
- arrow:: datatypes:: DataType :: Int64 => {
131
- Ok ( Timeline :: new_sequence ( field. name ( ) . clone ( ) ) )
132
- }
108
+ . zip ( timeline_names)
109
+ . map ( |( array, timeline_name) | {
110
+ let timeline = match array. data_type ( ) {
111
+ arrow:: datatypes:: DataType :: Int64 => Ok ( Timeline :: new_sequence ( timeline_name) ) ,
133
112
arrow:: datatypes:: DataType :: Timestamp ( _, _) => {
134
- Ok ( Timeline :: new_temporal ( field . name ( ) . clone ( ) ) )
113
+ Ok ( Timeline :: new_temporal ( timeline_name ) )
135
114
}
136
115
_ => Err ( ChunkError :: Malformed {
137
- reason : format ! ( "Invalid data_type for timeline: {}" , field . name ( ) ) ,
116
+ reason : format ! ( "Invalid data_type for timeline: {timeline_name}" ) ,
138
117
} ) ,
139
118
} ?;
119
+ let timeline_data =
120
+ TimeColumn :: read_array ( & ArrowArrayRef :: from ( array) ) . map_err ( |err| {
121
+ ChunkError :: Malformed {
122
+ reason : format ! ( "Invalid timeline {timeline_name}: {err}" ) ,
123
+ }
124
+ } ) ?;
140
125
Ok ( ( timeline, timeline_data) )
141
126
} )
142
127
. collect ( ) ;
@@ -148,31 +133,33 @@ pub fn build_chunk_from_components(
148
133
. collect ( ) ;
149
134
150
135
// Extract the component data
151
- let ( arrays, fields) : ( Vec < ArrowArrayRef > , Vec < ArrowField > ) = itertools:: process_results (
152
- components_per_descr. iter ( ) . map ( |( component_descr, array) | {
153
- array_to_rust ( & array, & descriptor_to_rust ( & component_descr) ?)
154
- } ) ,
155
- |iter| iter. unzip ( ) ,
156
- ) ?;
136
+ let ( arrays, component_descrs) : ( Vec < ArrowArrayRef > , Vec < ComponentDescriptor > ) =
137
+ itertools:: process_results (
138
+ components_per_descr. iter ( ) . map ( |( component_descr, array) | {
139
+ let component_descr = descriptor_to_rust ( & component_descr) ?;
140
+ array_to_rust ( & array) . map ( |array| ( array, component_descr) )
141
+ } ) ,
142
+ |iter| iter. unzip ( ) ,
143
+ ) ?;
157
144
158
145
let components: Result < Vec < ( ComponentDescriptor , _ ) > , ChunkError > = arrays
159
146
. into_iter ( )
160
- . zip ( fields )
161
- . map ( |( value , field ) | {
162
- let batch = if let Some ( batch) = value . downcast_array_ref :: < ArrowListArray > ( ) {
147
+ . zip ( component_descrs )
148
+ . map ( |( list_array , descr ) | {
149
+ let batch = if let Some ( batch) = list_array . downcast_array_ref :: < ArrowListArray > ( ) {
163
150
batch. clone ( )
164
151
} else {
165
152
let offsets =
166
- ArrowOffsetBuffer :: from_lengths ( std:: iter:: repeat ( 1 ) . take ( value . len ( ) ) ) ;
167
- let field = ArrowField :: new ( "item" , value . data_type ( ) . clone ( ) , true ) . into ( ) ;
168
- ArrowListArray :: try_new ( field, offsets, value , None ) . map_err ( |err| {
153
+ ArrowOffsetBuffer :: from_lengths ( std:: iter:: repeat ( 1 ) . take ( list_array . len ( ) ) ) ;
154
+ let field = ArrowField :: new ( "item" , list_array . data_type ( ) . clone ( ) , true ) . into ( ) ;
155
+ ArrowListArray :: try_new ( field, offsets, list_array , None ) . map_err ( |err| {
169
156
ChunkError :: Malformed {
170
157
reason : format ! ( "Failed to wrap in List array: {err}" ) ,
171
158
}
172
159
} ) ?
173
160
} ;
174
161
175
- Ok ( ( ComponentDescriptor :: new ( field . name ( ) . clone ( ) ) , batch) )
162
+ Ok ( ( descr , batch) )
176
163
} )
177
164
. collect ( ) ;
178
165
0 commit comments