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

Refactor TimeColumnDescriptor #8658

Merged
merged 5 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
55 changes: 16 additions & 39 deletions crates/store/re_chunk_store/src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::collections::{BTreeMap, BTreeSet};
use std::ops::Deref;
use std::ops::DerefMut;

use arrow::datatypes::DataType as ArrowDatatype;
use arrow2::{
array::ListArray as ArrowListArray,
datatypes::{DataType as Arrow2Datatype, Field as Arrow2Field},
Expand Down Expand Up @@ -45,7 +46,7 @@ impl ColumnDescriptor {
#[inline]
pub fn datatype(&self) -> Arrow2Datatype {
match self {
Self::Time(descr) => descr.datatype.clone(),
Self::Time(descr) => descr.datatype().into(),
Self::Component(descr) => descr.returned_datatype(),
}
}
Expand Down Expand Up @@ -76,39 +77,15 @@ impl ColumnDescriptor {
}

/// Describes a time column, such as `log_time`.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct TimeColumnDescriptor {
/// The timeline this column is associated with.
pub timeline: Timeline,

/// The Arrow datatype of the column.
pub datatype: Arrow2Datatype,
}

impl PartialOrd for TimeColumnDescriptor {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}

impl Ord for TimeColumnDescriptor {
#[inline]
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
let Self {
timeline,
datatype: _,
} = self;
timeline.cmp(&other.timeline)
}
}

impl TimeColumnDescriptor {
fn metadata(&self) -> arrow2::datatypes::Metadata {
let Self {
timeline,
datatype: _,
} = self;
let Self { timeline } = self;

std::iter::once(Some((
"sorbet.index_name".to_owned(),
Expand All @@ -118,13 +95,18 @@ impl TimeColumnDescriptor {
.collect()
}

#[inline]
pub fn datatype(&self) -> ArrowDatatype {
self.timeline.datatype()
}

#[inline]
// Time column must be nullable since static data doesn't have a time.
pub fn to_arrow_field(&self) -> Arrow2Field {
let Self { timeline, datatype } = self;
let Self { timeline } = self;
Arrow2Field::new(
timeline.name().to_string(),
datatype.clone(),
timeline.datatype().into(),
true, /* nullable */
)
.with_metadata(self.metadata())
Expand Down Expand Up @@ -705,12 +687,10 @@ impl ChunkStore {
pub fn schema(&self) -> Vec<ColumnDescriptor> {
re_tracing::profile_function!();

let timelines = self.all_timelines_sorted().into_iter().map(|timeline| {
ColumnDescriptor::Time(TimeColumnDescriptor {
timeline,
datatype: timeline.datatype().into(),
})
});
let timelines = self
.all_timelines_sorted()
.into_iter()
.map(|timeline| ColumnDescriptor::Time(TimeColumnDescriptor { timeline }));

let mut components = self
.per_column_metadata
Expand Down Expand Up @@ -780,10 +760,7 @@ impl ChunkStore {
.copied()
.unwrap_or_else(|| Timeline::new_temporal(selector.timeline));

TimeColumnDescriptor {
timeline,
datatype: timeline.datatype().into(),
}
TimeColumnDescriptor { timeline }
}

/// Given a [`ComponentColumnSelector`], returns the corresponding [`ComponentColumnDescriptor`].
Expand Down
5 changes: 2 additions & 3 deletions crates/store/re_dataframe/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ impl<E: StorageEngineLike> QueryHandle<E> {
// TODO(cmc): I picked a sequence here because I have to pick something.
// It doesn't matter, only the name will remain in the Arrow schema anyhow.
timeline: Timeline::new_sequence(*selected_timeline),
datatype: arrow2::datatypes::DataType::Null,
emilk marked this conversation as resolved.
Show resolved Hide resolved
}),
)
},
Expand Down Expand Up @@ -2029,7 +2028,7 @@ mod tests {
[
Int64[10, 20, 30, 40, 50, 60, 70],
Int64[10, 20, 30, 40, 50, 60, 70],
NullArray(7),
Int64[None, None, None, None, None, None, None],
]\
",
);
Expand Down Expand Up @@ -2241,7 +2240,7 @@ mod tests {
[
Int64[30, 40, 50, 70],
Timestamp(Nanosecond, None)[None, None, None, None],
NullArray(4),
Int64[None, None, None, None],
NullArray(4),
ListArray[[2], [3], [4], [6]],
ListArray[[c], [c], [c], [c]],
Expand Down
Loading