@@ -4,6 +4,7 @@ use arrow::array::Array as _;
4
4
use arrow:: array:: ArrayRef as ArrowArrayRef ;
5
5
6
6
use re_log_types:: { TimeInt , TimelineName } ;
7
+ use re_types_core:: ComponentDescriptor ;
7
8
use re_types_core:: { Component , ComponentName } ;
8
9
9
10
use crate :: { Chunk , ChunkResult , RowId } ;
@@ -258,20 +259,45 @@ impl UnitChunkShared {
258
259
impl UnitChunkShared {
259
260
// --- Batch ---
260
261
262
+ /// Returns the raw data for the specified component name.
263
+ ///
264
+ /// Indetermined which batch is returned if there are multiple components with the same name.
265
+ /// TODO(#6889): Can we remove this method?
266
+ #[ inline]
267
+ pub fn component_batch_raw_by_component_name (
268
+ & self ,
269
+ component_name : ComponentName ,
270
+ ) -> Option < ArrowArrayRef > {
271
+ debug_assert ! ( self . num_rows( ) == 1 ) ;
272
+ self . components
273
+ . get_by_component_name ( component_name)
274
+ . next ( )
275
+ . and_then ( |list_array| list_array. is_valid ( 0 ) . then ( || list_array. value ( 0 ) ) )
276
+ }
277
+
261
278
/// Returns the raw data for the specified component.
262
279
#[ inline]
263
- pub fn component_batch_raw ( & self , component_name : & ComponentName ) -> Option < ArrowArrayRef > {
280
+ pub fn component_batch_raw (
281
+ & self ,
282
+ component_descr : & ComponentDescriptor ,
283
+ ) -> Option < ArrowArrayRef > {
264
284
debug_assert ! ( self . num_rows( ) == 1 ) ;
265
- self . get_first_component ( * component_name)
285
+ self . components
286
+ . get ( component_descr)
266
287
. and_then ( |list_array| list_array. is_valid ( 0 ) . then ( || list_array. value ( 0 ) ) )
267
288
}
268
289
269
290
/// Returns the deserialized data for the specified component.
270
291
///
271
292
/// Returns an error if the data cannot be deserialized.
293
+ /// In debug builds, panics if the descriptor doesn't have the same component name as the component type.
272
294
#[ inline]
273
- pub fn component_batch < C : Component > ( & self ) -> Option < ChunkResult < Vec < C > > > {
274
- let data = C :: from_arrow ( & * self . component_batch_raw ( & C :: name ( ) ) ?) ;
295
+ pub fn component_batch < C : Component > (
296
+ & self ,
297
+ component_descr : & ComponentDescriptor ,
298
+ ) -> Option < ChunkResult < Vec < C > > > {
299
+ debug_assert_eq ! ( C :: name( ) , component_descr. component_name) ;
300
+ let data = C :: from_arrow ( & * self . component_batch_raw ( component_descr) ?) ;
275
301
Some ( data. map_err ( Into :: into) )
276
302
}
277
303
@@ -283,10 +309,10 @@ impl UnitChunkShared {
283
309
#[ inline]
284
310
pub fn component_instance_raw (
285
311
& self ,
286
- component_name : & ComponentName ,
312
+ component_descr : & ComponentDescriptor ,
287
313
instance_index : usize ,
288
314
) -> Option < ChunkResult < ArrowArrayRef > > {
289
- let array = self . component_batch_raw ( component_name ) ?;
315
+ let array = self . component_batch_raw ( component_descr ) ?;
290
316
if array. len ( ) > instance_index {
291
317
Some ( Ok ( array. slice ( instance_index, 1 ) ) )
292
318
} else {
@@ -301,12 +327,15 @@ impl UnitChunkShared {
301
327
/// Returns the deserialized data for the specified component at the given instance index.
302
328
///
303
329
/// Returns an error if the data cannot be deserialized, or if the instance index is out of bounds.
330
+ /// In debug builds, panics if the descriptor doesn't have the same component name as the component type.
304
331
#[ inline]
305
332
pub fn component_instance < C : Component > (
306
333
& self ,
334
+ component_descr : & ComponentDescriptor ,
307
335
instance_index : usize ,
308
336
) -> Option < ChunkResult < C > > {
309
- let res = self . component_instance_raw ( & C :: name ( ) , instance_index) ?;
337
+ debug_assert_eq ! ( C :: name( ) , component_descr. component_name) ;
338
+ let res = self . component_instance_raw ( component_descr, instance_index) ?;
310
339
311
340
let array = match res {
312
341
Ok ( array) => array,
@@ -327,9 +356,9 @@ impl UnitChunkShared {
327
356
#[ inline]
328
357
pub fn component_mono_raw (
329
358
& self ,
330
- component_name : & ComponentName ,
359
+ component_descr : & ComponentDescriptor ,
331
360
) -> Option < ChunkResult < ArrowArrayRef > > {
332
- let array = self . component_batch_raw ( component_name ) ?;
361
+ let array = self . component_batch_raw ( component_descr ) ?;
333
362
if array. len ( ) == 1 {
334
363
Some ( Ok ( array. slice ( 0 , 1 ) ) )
335
364
} else {
@@ -344,9 +373,14 @@ impl UnitChunkShared {
344
373
/// Returns the deserialized data for the specified component, assuming a mono-batch.
345
374
///
346
375
/// Returns an error if the data cannot be deserialized, or if the underlying batch is not of unit length.
376
+ /// In debug builds, panics if the descriptor doesn't have the same component name as the component type.
347
377
#[ inline]
348
- pub fn component_mono < C : Component > ( & self ) -> Option < ChunkResult < C > > {
349
- let res = self . component_mono_raw ( & C :: name ( ) ) ?;
378
+ pub fn component_mono < C : Component > (
379
+ & self ,
380
+ component_descr : & ComponentDescriptor ,
381
+ ) -> Option < ChunkResult < C > > {
382
+ debug_assert_eq ! ( C :: name( ) , component_descr. component_name) ;
383
+ let res = self . component_mono_raw ( component_descr) ?;
350
384
351
385
let array = match res {
352
386
Ok ( array) => array,
0 commit comments