Skip to content

Commit 1ee93eb

Browse files
authored
Add ComponentDescriptorRef to re_sorbet (#9043)
### Related * Related to #9034 * Required for #9018 ### What This PR introduce the `ComponentDescriptorRef` type to `re_sorbet`. It's like `ComponentDescriptor` but: - It has refs instead of owned copies. - It has a `RowId` enum (which would be difficult to add to `ComponentDescriptor` because of the ramifications on the dataframe API—let's wait for the RowID <-> Index column merge for that).
1 parent 46683ce commit 1ee93eb

File tree

6 files changed

+79
-4
lines changed

6 files changed

+79
-4
lines changed

crates/store/re_sorbet/src/column_descriptor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub enum ColumnError {
2828
// See:
2929
// * [`IndexColumnDescriptor`]
3030
// * [`ComponentColumnDescriptor`]
31+
//TODO(#9034): This should support RowId as well, but this has ramifications on the dataframe API.
3132
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
3233
pub enum ColumnDescriptor {
3334
Time(IndexColumnDescriptor),
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use crate::{
2+
ColumnDescriptor, ComponentColumnDescriptor, IndexColumnDescriptor, RowIdColumnDescriptor,
3+
};
4+
5+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
6+
pub enum ColumnDescriptorRef<'a> {
7+
RowId(&'a RowIdColumnDescriptor),
8+
Time(&'a IndexColumnDescriptor),
9+
Component(&'a ComponentColumnDescriptor),
10+
}
11+
12+
impl ColumnDescriptorRef<'_> {
13+
/// Human-readable name for the column.
14+
#[inline]
15+
pub fn name(&self) -> String {
16+
match self {
17+
Self::RowId(descr) => descr.name().to_owned(),
18+
Self::Time(descr) => descr.timeline.name().to_string(),
19+
Self::Component(descr) => descr.component_name.short_name().to_owned(),
20+
}
21+
}
22+
}
23+
24+
impl<'a> From<&'a ColumnDescriptor> for ColumnDescriptorRef<'a> {
25+
fn from(desc: &'a ColumnDescriptor) -> Self {
26+
match desc {
27+
ColumnDescriptor::Time(desc) => Self::Time(desc),
28+
ColumnDescriptor::Component(desc) => Self::Component(desc),
29+
}
30+
}
31+
}
32+
33+
impl<'a> From<&'a RowIdColumnDescriptor> for ColumnDescriptorRef<'a> {
34+
fn from(desc: &'a RowIdColumnDescriptor) -> Self {
35+
Self::RowId(desc)
36+
}
37+
}
38+
39+
impl<'a> From<&'a IndexColumnDescriptor> for ColumnDescriptorRef<'a> {
40+
fn from(desc: &'a IndexColumnDescriptor) -> Self {
41+
Self::Time(desc)
42+
}
43+
}
44+
45+
impl<'a> From<&'a ComponentColumnDescriptor> for ColumnDescriptorRef<'a> {
46+
fn from(desc: &'a ComponentColumnDescriptor) -> Self {
47+
Self::Component(desc)
48+
}
49+
}

crates/store/re_sorbet/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
mod chunk_batch;
1919
mod chunk_schema;
2020
mod column_descriptor;
21+
mod column_descriptor_ref;
2122
mod column_kind;
2223
mod component_column_descriptor;
2324
mod error;
@@ -33,6 +34,7 @@ pub use self::{
3334
chunk_batch::{ChunkBatch, MismatchedChunkSchemaError},
3435
chunk_schema::ChunkSchema,
3536
column_descriptor::{ColumnDescriptor, ColumnError},
37+
column_descriptor_ref::ColumnDescriptorRef,
3638
column_kind::ColumnKind,
3739
component_column_descriptor::ComponentColumnDescriptor,
3840
error::SorbetError,

crates/store/re_sorbet/src/row_id_column_descriptor.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ impl RowIdColumnDescriptor {
3434
Self {}
3535
}
3636

37+
/// Human-readable name for this column.
38+
#[inline]
39+
#[expect(clippy::unused_self)]
40+
pub fn name(&self) -> &'static str {
41+
"Row ID"
42+
}
43+
3744
#[inline]
3845
pub fn to_arrow_field(&self) -> ArrowField {
3946
let Self {} = self;

crates/store/re_sorbet/src/sorbet_batch.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use arrow::{
1010
use re_arrow_util::{into_arrow_ref, ArrowArrayDowncastRef};
1111

1212
use crate::{
13-
ArrowBatchMetadata, ComponentColumnDescriptor, IndexColumnDescriptor, RowIdColumnDescriptor,
14-
SorbetError, SorbetSchema,
13+
ArrowBatchMetadata, ColumnDescriptorRef, ComponentColumnDescriptor, IndexColumnDescriptor,
14+
RowIdColumnDescriptor, SorbetError, SorbetSchema,
1515
};
1616

1717
/// Any rerun-compatible [`ArrowRecordBatch`].
@@ -82,6 +82,11 @@ impl SorbetBatch {
8282
})
8383
}
8484

85+
/// All the columns along with their descriptors.
86+
pub fn all_columns(&self) -> impl Iterator<Item = (ColumnDescriptorRef<'_>, &ArrowArrayRef)> {
87+
self.schema.columns.descriptors().zip(self.batch.columns())
88+
}
89+
8590
/// The columns of the indices (timelines).
8691
pub fn index_columns(&self) -> impl Iterator<Item = (&IndexColumnDescriptor, &ArrowArrayRef)> {
8792
let num_row_id_columns = self.schema.columns.row_id.is_some() as usize;

crates/store/re_sorbet/src/sorbet_columns.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use nohash_hasher::IntSet;
44
use re_log_types::EntityPath;
55

66
use crate::{
7-
ColumnDescriptor, ColumnKind, ComponentColumnDescriptor, IndexColumnDescriptor,
8-
RowIdColumnDescriptor, SorbetError,
7+
ColumnDescriptor, ColumnDescriptorRef, ColumnKind, ComponentColumnDescriptor,
8+
IndexColumnDescriptor, RowIdColumnDescriptor, SorbetError,
99
};
1010

1111
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -51,6 +51,17 @@ impl SorbetColumnDescriptors {
5151
.collect()
5252
}
5353

54+
/// Returns all columns, including the `row_id` column.
55+
///
56+
/// See also [`Self::indices_and_components`].
57+
pub fn descriptors(&self) -> impl Iterator<Item = ColumnDescriptorRef<'_>> + '_ {
58+
self.row_id
59+
.iter()
60+
.map(ColumnDescriptorRef::from)
61+
.chain(self.indices.iter().map(ColumnDescriptorRef::from))
62+
.chain(self.components.iter().map(ColumnDescriptorRef::from))
63+
}
64+
5465
/// Returns all indices and then all components;
5566
/// skipping the `row_id` column.
5667
///

0 commit comments

Comments
 (0)