Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re_query: up to date with latest data types and structures #1828

Merged
merged 5 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/re_log_types/src/component_types/instance_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ impl InstanceKey {
/// for example all points in a point cloud entity.
pub const SPLAT: Self = Self(u64::MAX);

#[allow(clippy::should_implement_trait)]
#[inline]
pub fn from_iter(it: impl IntoIterator<Item = impl Into<Self>>) -> Vec<Self> {
it.into_iter().map(Into::into).collect::<Vec<_>>()
}

/// Are we referring to all instances of the entity (e.g. all points in a point cloud entity)?
///
/// The opposite of [`Self::is_specific`].
Expand Down
30 changes: 30 additions & 0 deletions crates/re_log_types/src/data_cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,36 @@ impl DataCell {
{
self.try_to_native().unwrap()
}

/// Returns the contents of the cell as an iterator of native optional components.
///
/// Fails if the underlying arrow data cannot be deserialized into `C`.
//
// TODO(#1694): There shouldn't need to be HRTBs (Higher-Rank Trait Bounds) here.
#[inline]
pub fn try_to_native_opt<C: DeserializableComponent>(
&self,
) -> DataCellResult<impl Iterator<Item = Option<C>> + '_>
where
for<'a> &'a C::ArrayType: IntoIterator,
{
use arrow2_convert::deserialize::arrow_array_deserialize_iterator;
arrow_array_deserialize_iterator(&*self.inner.values).map_err(Into::into)
}

/// Returns the contents of the cell as an iterator of native optional components.
///
/// Panics if the underlying arrow data cannot be deserialized into `C`.
/// See [`Self::try_to_native_opt`] for a fallible alternative.
//
// TODO(#1694): There shouldn't need to be HRTBs here.
#[inline]
pub fn to_native_opt<C: DeserializableComponent>(&self) -> impl Iterator<Item = Option<C>> + '_
where
for<'a> &'a C::ArrayType: IntoIterator,
{
self.try_to_native_opt().unwrap()
}
}

impl DataCell {
Expand Down
13 changes: 5 additions & 8 deletions crates/re_query/src/dataframe_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,17 @@ impl ComponentWithInstances {
where
for<'a> &'a C0::ArrayType: IntoIterator,
{
if C0::name() != self.name {
if C0::name() != self.name() {
return Err(QueryError::TypeMismatch {
actual: self.name,
actual: self.name(),
requested: C0::name(),
});
}

let instance_keys: Vec<Option<InstanceKey>> =
self.iter_instance_keys()?.map(Some).collect_vec();

let values =
arrow_array_deserialize_iterator::<Option<C0>>(self.values.as_ref())?.collect_vec();
let values = self.values.try_to_native_opt()?.collect_vec();

df_builder2::<InstanceKey, C0>(&instance_keys, &values)
}
Expand All @@ -160,8 +159,7 @@ where
pub fn as_df1(&self) -> crate::Result<DataFrame> {
let instance_keys = self.primary.iter_instance_keys()?.map(Some).collect_vec();

let primary_values =
arrow_array_deserialize_iterator(self.primary.values.as_ref())?.collect_vec();
let primary_values = self.primary.values.try_to_native_opt()?.collect_vec();

df_builder2::<InstanceKey, Primary>(&instance_keys, &primary_values)
}
Expand All @@ -173,8 +171,7 @@ where
{
let instance_keys = self.primary.iter_instance_keys()?.map(Some).collect_vec();

let primary_values =
arrow_array_deserialize_iterator(self.primary.values.as_ref())?.collect_vec();
let primary_values = self.primary.values.try_to_native_opt()?.collect_vec();

let c1_values = self.iter_component::<C1>()?.collect_vec();

Expand Down
Loading