Skip to content

Commit

Permalink
Dataframe v2: new static semantics (#7696)
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc authored Oct 11, 2024
1 parent 0045de5 commit b32e69c
Show file tree
Hide file tree
Showing 6 changed files with 573 additions and 383 deletions.
45 changes: 14 additions & 31 deletions crates/store/re_chunk_store/src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,7 @@ pub type IndexRange = ResolvedTimeRange;
/// ```
//
// TODO(cmc): ideally we'd like this to be the same type as the one used in the blueprint, possibly?
// TODO(cmc): Get rid of all re_dataframe (as opposed to re_dataframe) stuff and rename this.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Default, Debug, Clone, PartialEq, Eq, Hash)]
pub struct QueryExpression {
/// The subset of the database that the query will run on: a set of [`EntityPath`]s and their
/// associated [`ComponentName`]s.
Expand Down Expand Up @@ -619,17 +618,20 @@ pub struct QueryExpression {
/// Only rows where at least 1 column contains non-null data at that index will be kept in the
/// final dataset.
///
/// Example: `Timeline("frame")`.
/// If left unspecified, the results will only contain static data.
///
/// Examples: `Some(Timeline("frame"))`, `None` (only static data).
//
// TODO(cmc): this has to be a selector otherwise this is a horrible UX.
pub filtered_index: Timeline,
pub filtered_index: Option<Timeline>,

/// The range of index values used to filter out _rows_ from the view contents.
///
/// Only rows where at least 1 of the view-contents contains non-null data within that range will be kept in
/// the final dataset.
///
/// This is ignored if [`QueryExpression::using_index_values`] is set.
/// * This has no effect if `filtered_index` isn't set.
/// * This has no effect if [`QueryExpression::using_index_values`] is set.
///
/// Example: `ResolvedTimeRange(10, 20)`.
pub filtered_index_range: Option<IndexRange>,
Expand All @@ -639,7 +641,9 @@ pub struct QueryExpression {
/// Only rows where at least 1 column contains non-null data at these specific values will be kept
/// in the final dataset.
///
/// This is ignored if [`QueryExpression::using_index_values`] is set.
/// * This has no effect if `filtered_index` isn't set.
/// * This has no effect if [`QueryExpression::using_index_values`] is set.
/// * Using [`TimeInt::STATIC`] as index value has no effect.
///
/// Example: `[TimeInt(12), TimeInt(14)]`.
pub filtered_index_values: Option<BTreeSet<IndexValue>>,
Expand All @@ -651,10 +655,10 @@ pub struct QueryExpression {
/// The semantics of the query are consistent with all other settings: the results will be
/// sorted on the `filtered_index`, and only contain unique index values.
///
/// The order of the samples will be respected in the final result.
///
/// If [`QueryExpression::using_index_values`] is set, it overrides both [`QueryExpression::filtered_index_range`]
/// and [`QueryExpression::filtered_index_values`].
/// * This has no effect if `filtered_index` isn't set.
/// * If set, this overrides both [`QueryExpression::filtered_index_range`] and
/// [`QueryExpression::filtered_index_values`].
/// * Using [`TimeInt::STATIC`] as index value has no effect.
///
/// Example: `[TimeInt(12), TimeInt(14)]`.
pub using_index_values: Option<BTreeSet<IndexValue>>,
Expand Down Expand Up @@ -685,27 +689,6 @@ pub struct QueryExpression {
pub selection: Option<Vec<ColumnSelector>>,
}

impl QueryExpression {
#[inline]
pub fn new(index: impl Into<Timeline>) -> Self {
let index = index.into();

Self {
view_contents: None,
include_semantically_empty_columns: false,
include_indicator_columns: false,
include_tombstone_columns: false,
filtered_index: index,
filtered_index_range: None,
filtered_index_values: None,
using_index_values: None,
filtered_point_of_view: None,
sparse_fill_strategy: SparseFillStrategy::None,
selection: None,
}
}
}

// ---

impl ChunkStore {
Expand Down
21 changes: 12 additions & 9 deletions crates/store/re_dataframe/examples/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,18 @@ fn main() -> anyhow::Result<()> {
cache: &query_cache,
};

let mut query = QueryExpression::new(timeline);
query.view_contents = Some(
query_engine
.iter_entity_paths(&entity_path_filter)
.map(|entity_path| (entity_path, None))
.collect(),
);
query.filtered_index_range = Some(ResolvedTimeRange::new(time_from, time_to));
query.sparse_fill_strategy = SparseFillStrategy::LatestAtGlobal;
let query = QueryExpression {
filtered_index: Some(timeline),
view_contents: Some(
query_engine
.iter_entity_paths(&entity_path_filter)
.map(|entity_path| (entity_path, None))
.collect(),
),
filtered_index_range: Some(ResolvedTimeRange::new(time_from, time_to)),
sparse_fill_strategy: SparseFillStrategy::LatestAtGlobal,
..Default::default()
};
eprintln!("{query:#?}:");

let query_handle = query_engine.query(query.clone());
Expand Down
Loading

0 comments on commit b32e69c

Please sign in to comment.