Skip to content

Commit

Permalink
Revert "Remove LoggableBatch::num_instances (#7258)"
Browse files Browse the repository at this point in the history
This reverts commit b0aaeb2.
  • Loading branch information
emilk committed Aug 28, 2024
1 parent 13aaf3e commit 06f057f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
14 changes: 12 additions & 2 deletions crates/store/re_types_core/src/archetype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,15 @@ impl<A: Archetype> crate::LoggableBatch for GenericIndicatorComponent<A> {
.into()
}

#[inline]
fn num_instances(&self) -> usize {
1
}

#[inline]
fn to_arrow(&self) -> SerializationResult<Box<dyn arrow2::array::Array>> {
let datatype = arrow2::datatypes::DataType::Null;
Ok(arrow2::array::NullArray::new(datatype, 1).boxed())
Ok(arrow2::array::NullArray::new(datatype, self.num_instances()).boxed())
}
}

Expand Down Expand Up @@ -250,10 +255,15 @@ impl crate::LoggableBatch for NamedIndicatorComponent {
self.0
}

#[inline]
fn num_instances(&self) -> usize {
1
}

#[inline]
fn to_arrow(&self) -> SerializationResult<Box<dyn arrow2::array::Array>> {
let datatype = arrow2::datatypes::DataType::Null;
Ok(arrow2::array::NullArray::new(datatype, 1).boxed())
Ok(arrow2::array::NullArray::new(datatype, self.num_instances()).boxed())
}
}

Expand Down
58 changes: 58 additions & 0 deletions crates/store/re_types_core/src/loggable_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ pub trait LoggableBatch {
/// The fully-qualified name of this batch, e.g. `rerun.datatypes.Vec2D`.
fn name(&self) -> Self::Name;

/// The number of component instances stored into this batch.
fn num_instances(&self) -> usize;

/// Serializes the batch into an Arrow array.
fn to_arrow(&self) -> SerializationResult<Box<dyn ::arrow2::array::Array>>;
}
Expand Down Expand Up @@ -87,6 +90,11 @@ impl<'a> LoggableBatch for MaybeOwnedComponentBatch<'a> {
self.as_ref().name()
}

#[inline]
fn num_instances(&self) -> usize {
self.as_ref().num_instances()
}

#[inline]
fn to_arrow(&self) -> SerializationResult<Box<dyn ::arrow2::array::Array>> {
self.as_ref().to_arrow()
Expand All @@ -105,6 +113,11 @@ impl<L: Clone + Loggable> LoggableBatch for L {
L::name()
}

#[inline]
fn num_instances(&self) -> usize {
1
}

#[inline]
fn to_arrow(&self) -> SerializationResult<Box<dyn ::arrow2::array::Array>> {
L::to_arrow([std::borrow::Cow::Borrowed(self)])
Expand All @@ -123,6 +136,11 @@ impl<L: Clone + Loggable> LoggableBatch for Option<L> {
L::name()
}

#[inline]
fn num_instances(&self) -> usize {
self.is_some() as usize
}

#[inline]
fn to_arrow(&self) -> SerializationResult<Box<dyn ::arrow2::array::Array>> {
L::to_arrow(self.iter().map(|v| std::borrow::Cow::Borrowed(v)))
Expand All @@ -141,6 +159,11 @@ impl<L: Clone + Loggable> LoggableBatch for Vec<L> {
L::name()
}

#[inline]
fn num_instances(&self) -> usize {
self.len()
}

#[inline]
fn to_arrow(&self) -> SerializationResult<Box<dyn ::arrow2::array::Array>> {
L::to_arrow(self.iter().map(|v| std::borrow::Cow::Borrowed(v)))
Expand All @@ -159,6 +182,11 @@ impl<L: Loggable> LoggableBatch for Vec<Option<L>> {
L::name()
}

#[inline]
fn num_instances(&self) -> usize {
self.len()
}

#[inline]
fn to_arrow(&self) -> SerializationResult<Box<dyn ::arrow2::array::Array>> {
L::to_arrow_opt(
Expand All @@ -180,6 +208,11 @@ impl<L: Loggable, const N: usize> LoggableBatch for [L; N] {
L::name()
}

#[inline]
fn num_instances(&self) -> usize {
N
}

#[inline]
fn to_arrow(&self) -> SerializationResult<Box<dyn ::arrow2::array::Array>> {
L::to_arrow(self.iter().map(|v| std::borrow::Cow::Borrowed(v)))
Expand All @@ -198,6 +231,11 @@ impl<L: Loggable, const N: usize> LoggableBatch for [Option<L>; N] {
L::name()
}

#[inline]
fn num_instances(&self) -> usize {
N
}

#[inline]
fn to_arrow(&self) -> SerializationResult<Box<dyn ::arrow2::array::Array>> {
L::to_arrow_opt(
Expand All @@ -219,6 +257,11 @@ impl<'a, L: Loggable> LoggableBatch for &'a [L] {
L::name()
}

#[inline]
fn num_instances(&self) -> usize {
self.len()
}

#[inline]
fn to_arrow(&self) -> SerializationResult<Box<dyn ::arrow2::array::Array>> {
L::to_arrow(self.iter().map(|v| std::borrow::Cow::Borrowed(v)))
Expand All @@ -237,6 +280,11 @@ impl<'a, L: Loggable> LoggableBatch for &'a [Option<L>] {
L::name()
}

#[inline]
fn num_instances(&self) -> usize {
self.len()
}

#[inline]
fn to_arrow(&self) -> SerializationResult<Box<dyn ::arrow2::array::Array>> {
L::to_arrow_opt(
Expand All @@ -258,6 +306,11 @@ impl<'a, L: Loggable, const N: usize> LoggableBatch for &'a [L; N] {
L::name()
}

#[inline]
fn num_instances(&self) -> usize {
N
}

#[inline]
fn to_arrow(&self) -> SerializationResult<Box<dyn ::arrow2::array::Array>> {
L::to_arrow(self.iter().map(|v| std::borrow::Cow::Borrowed(v)))
Expand All @@ -276,6 +329,11 @@ impl<'a, L: Loggable, const N: usize> LoggableBatch for &'a [Option<L>; N] {
L::name()
}

#[inline]
fn num_instances(&self) -> usize {
N
}

#[inline]
fn to_arrow(&self) -> SerializationResult<Box<dyn ::arrow2::array::Array>> {
L::to_arrow_opt(
Expand Down

0 comments on commit 06f057f

Please sign in to comment.