Skip to content

Commit

Permalink
port re_query's range test suite 1:1
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Jan 11, 2024
1 parent 6383589 commit 2d39d88
Show file tree
Hide file tree
Showing 2 changed files with 424 additions and 46 deletions.
84 changes: 38 additions & 46 deletions crates/re_query_cache/tests/latest_at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
use itertools::Itertools as _;

use re_data_store::{DataStore, LatestAtQuery};
use re_log_types::{build_frame_nr, DataRow, EntityPath, RowId, TimePoint};
use re_query_cache::query_archetype_pov1_comp1;
use re_types::{
archetypes::Points2D,
components::{Color, InstanceKey, Position2D},
use re_log_types::{
build_frame_nr,
example_components::{MyColor, MyPoint, MyPoints},
DataRow, EntityPath, RowId, TimePoint,
};
use re_types_core::Loggable as _;
use re_query_cache::query_archetype_pov1_comp1;
use re_types_core::{components::InstanceKey, Loggable as _};

// ---

Expand All @@ -27,13 +27,13 @@ fn simple_query() {
let timepoint = [build_frame_nr(123.into())];

// Create some positions with implicit instances
let positions = vec![Position2D::new(1.0, 2.0), Position2D::new(3.0, 4.0)];
let positions = vec![MyPoint::new(1.0, 2.0), MyPoint::new(3.0, 4.0)];
let row = DataRow::from_cells1_sized(RowId::new(), ent_path, timepoint, 2, positions).unwrap();
store.insert_row(&row).unwrap();

// Assign one of them a color with an explicit instance
let color_instances = vec![InstanceKey(1)];
let colors = vec![Color::from_rgb(255, 0, 0)];
let colors = vec![MyColor::from_rgb(255, 0, 0)];
let row = DataRow::from_cells2_sized(
RowId::new(),
ent_path,
Expand All @@ -44,7 +44,6 @@ fn simple_query() {
.unwrap();
store.insert_row(&row).unwrap();

// Retrieve the view
let query = re_data_store::LatestAtQuery::new(timepoint[0].0, timepoint[0].1);
query_and_compare(&store, &query, &ent_path.into());
}
Expand All @@ -61,18 +60,17 @@ fn timeless_query() {
let timepoint = [build_frame_nr(123.into())];

// Create some positions with implicit instances
let positions = vec![Position2D::new(1.0, 2.0), Position2D::new(3.0, 4.0)];
let positions = vec![MyPoint::new(1.0, 2.0), MyPoint::new(3.0, 4.0)];
let row = DataRow::from_cells1_sized(RowId::new(), ent_path, timepoint, 2, positions).unwrap();
store.insert_row(&row).unwrap();

// Assign one of them a color with an explicit instance.. timelessly!
let color_instances = vec![InstanceKey(1)];
let colors = vec![Color::from_rgb(255, 0, 0)];
let colors = vec![MyColor::from_rgb(255, 0, 0)];
let row = DataRow::from_cells2_sized(RowId::new(), ent_path, [], 1, (color_instances, colors))
.unwrap();
store.insert_row(&row).unwrap();

// Retrieve the view
let query = re_data_store::LatestAtQuery::new(timepoint[0].0, timepoint[0].1);
query_and_compare(&store, &query, &ent_path.into());
}
Expand All @@ -89,16 +87,15 @@ fn no_instance_join_query() {
let timepoint = [build_frame_nr(123.into())];

// Create some positions with an implicit instance
let positions = vec![Position2D::new(1.0, 2.0), Position2D::new(3.0, 4.0)];
let positions = vec![MyPoint::new(1.0, 2.0), MyPoint::new(3.0, 4.0)];
let row = DataRow::from_cells1_sized(RowId::new(), ent_path, timepoint, 2, positions).unwrap();
store.insert_row(&row).unwrap();

// Assign them colors with explicit instances
let colors = vec![Color::from_rgb(255, 0, 0), Color::from_rgb(0, 255, 0)];
let colors = vec![MyColor::from_rgb(255, 0, 0), MyColor::from_rgb(0, 255, 0)];
let row = DataRow::from_cells1_sized(RowId::new(), ent_path, timepoint, 2, colors).unwrap();
store.insert_row(&row).unwrap();

// Retrieve the view
let query = re_data_store::LatestAtQuery::new(timepoint[0].0, timepoint[0].1);
query_and_compare(&store, &query, &ent_path.into());
}
Expand All @@ -115,11 +112,10 @@ fn missing_column_join_query() {
let timepoint = [build_frame_nr(123.into())];

// Create some positions with an implicit instance
let positions = vec![Position2D::new(1.0, 2.0), Position2D::new(3.0, 4.0)];
let positions = vec![MyPoint::new(1.0, 2.0), MyPoint::new(3.0, 4.0)];
let row = DataRow::from_cells1_sized(RowId::new(), ent_path, timepoint, 2, positions).unwrap();
store.insert_row(&row).unwrap();

// Retrieve the view
let query = re_data_store::LatestAtQuery::new(timepoint[0].0, timepoint[0].1);
query_and_compare(&store, &query, &ent_path.into());
}
Expand All @@ -136,13 +132,13 @@ fn splatted_query() {
let timepoint = [build_frame_nr(123.into())];

// Create some positions with implicit instances
let positions = vec![Position2D::new(1.0, 2.0), Position2D::new(3.0, 4.0)];
let positions = vec![MyPoint::new(1.0, 2.0), MyPoint::new(3.0, 4.0)];
let row = DataRow::from_cells1_sized(RowId::new(), ent_path, timepoint, 2, positions).unwrap();
store.insert_row(&row).unwrap();

// Assign all of them a color via splat
let color_instances = vec![InstanceKey::SPLAT];
let colors = vec![Color::from_rgb(255, 0, 0)];
let colors = vec![MyColor::from_rgb(255, 0, 0)];
let row = DataRow::from_cells2_sized(
RowId::new(),
ent_path,
Expand All @@ -153,7 +149,6 @@ fn splatted_query() {
.unwrap();
store.insert_row(&row).unwrap();

// Retrieve the view
let query = re_data_store::LatestAtQuery::new(timepoint[0].0, timepoint[0].1);
query_and_compare(&store, &query, &ent_path.into());
}
Expand All @@ -173,7 +168,7 @@ fn invalidation() {
);

// Create some positions with implicit instances
let positions = vec![Position2D::new(1.0, 2.0), Position2D::new(3.0, 4.0)];
let positions = vec![MyPoint::new(1.0, 2.0), MyPoint::new(3.0, 4.0)];
let row = DataRow::from_cells1_sized(
RowId::new(),
ent_path,
Expand All @@ -186,7 +181,7 @@ fn invalidation() {

// Assign one of them a color with an explicit instance
let color_instances = vec![InstanceKey(1)];
let colors = vec![Color::from_rgb(1, 2, 3)];
let colors = vec![MyColor::from_rgb(1, 2, 3)];
let row = DataRow::from_cells2_sized(
RowId::new(),
ent_path,
Expand All @@ -202,7 +197,7 @@ fn invalidation() {
// --- Modify present ---

// Modify the PoV component
let positions = vec![Position2D::new(10.0, 20.0), Position2D::new(30.0, 40.0)];
let positions = vec![MyPoint::new(10.0, 20.0), MyPoint::new(30.0, 40.0)];
let row = DataRow::from_cells1_sized(
RowId::new(),
ent_path,
Expand All @@ -216,7 +211,7 @@ fn invalidation() {
query_and_compare(&store, &query, &ent_path.into());

// Modify the optional component
let colors = vec![Color::from_rgb(4, 5, 6), Color::from_rgb(7, 8, 9)];
let colors = vec![MyColor::from_rgb(4, 5, 6), MyColor::from_rgb(7, 8, 9)];
let row =
DataRow::from_cells1_sized(RowId::new(), ent_path, present_data_timepoint, 2, colors)
.unwrap();
Expand All @@ -227,7 +222,7 @@ fn invalidation() {
// --- Modify past ---

// Modify the PoV component
let positions = vec![Position2D::new(100.0, 200.0), Position2D::new(300.0, 400.0)];
let positions = vec![MyPoint::new(100.0, 200.0), MyPoint::new(300.0, 400.0)];
let row = DataRow::from_cells1_sized(
RowId::new(),
ent_path,
Expand All @@ -241,7 +236,7 @@ fn invalidation() {
query_and_compare(&store, &query, &ent_path.into());

// Modify the optional component
let colors = vec![Color::from_rgb(10, 11, 12), Color::from_rgb(13, 14, 15)];
let colors = vec![MyColor::from_rgb(10, 11, 12), MyColor::from_rgb(13, 14, 15)];
let row =
DataRow::from_cells1_sized(RowId::new(), ent_path, past_data_timepoint, 2, colors)
.unwrap();
Expand All @@ -252,10 +247,7 @@ fn invalidation() {
// --- Modify future ---

// Modify the PoV component
let positions = vec![
Position2D::new(1000.0, 2000.0),
Position2D::new(3000.0, 4000.0),
];
let positions = vec![MyPoint::new(1000.0, 2000.0), MyPoint::new(3000.0, 4000.0)];
let row = DataRow::from_cells1_sized(
RowId::new(),
ent_path,
Expand All @@ -269,7 +261,7 @@ fn invalidation() {
query_and_compare(&store, &query, &ent_path.into());

// Modify the optional component
let colors = vec![Color::from_rgb(16, 17, 18)];
let colors = vec![MyColor::from_rgb(16, 17, 18)];
let row =
DataRow::from_cells1_sized(RowId::new(), ent_path, future_data_timepoint, 1, colors)
.unwrap();
Expand Down Expand Up @@ -312,19 +304,19 @@ fn invalidation() {
// # Expected: points=[[1,2,3]] colors=[]
//
// rr.set_time(2)
// rr.log_components("points", rr.components.Color(0xFF0000))
// rr.log_components("points", rr.components.MyColor(0xFF0000))
//
// # Do second query here: LatestAt(+inf)
// # Expected: points=[[1,2,3]] colors=[0xFF0000]
//
// rr.set_time(3)
// rr.log_components("points", rr.components.Color(0x0000FF))
// rr.log_components("points", rr.components.MyColor(0x0000FF))
//
// # Do third query here: LatestAt(+inf)
// # Expected: points=[[1,2,3]] colors=[0x0000FF]
//
// rr.set_time(3)
// rr.log_components("points", rr.components.Color(0x00FF00))
// rr.log_components("points", rr.components.MyColor(0x00FF00))
//
// # Do fourth query here: LatestAt(+inf)
// # Expected: points=[[1,2,3]] colors=[0x00FF00]
Expand All @@ -345,15 +337,15 @@ fn invalidation_of_future_optionals() {

let query_time = [build_frame_nr(9999.into())];

let positions = vec![Position2D::new(1.0, 2.0), Position2D::new(3.0, 4.0)];
let positions = vec![MyPoint::new(1.0, 2.0), MyPoint::new(3.0, 4.0)];
let row = DataRow::from_cells1_sized(RowId::new(), ent_path, timeless, 2, positions).unwrap();
store.insert_row(&row).unwrap();

let query = re_data_store::LatestAtQuery::new(query_time[0].0, query_time[0].1);
query_and_compare(&store, &query, &ent_path.into());

let color_instances = vec![InstanceKey::SPLAT];
let colors = vec![Color::from_rgb(255, 0, 0)];
let colors = vec![MyColor::from_rgb(255, 0, 0)];
let row =
DataRow::from_cells2_sized(RowId::new(), ent_path, frame2, 1, (color_instances, colors))
.unwrap();
Expand All @@ -363,7 +355,7 @@ fn invalidation_of_future_optionals() {
query_and_compare(&store, &query, &ent_path.into());

let color_instances = vec![InstanceKey::SPLAT];
let colors = vec![Color::from_rgb(0, 0, 255)];
let colors = vec![MyColor::from_rgb(0, 0, 255)];
let row =
DataRow::from_cells2_sized(RowId::new(), ent_path, frame3, 1, (color_instances, colors))
.unwrap();
Expand All @@ -373,7 +365,7 @@ fn invalidation_of_future_optionals() {
query_and_compare(&store, &query, &ent_path.into());

let color_instances = vec![InstanceKey::SPLAT];
let colors = vec![Color::from_rgb(0, 255, 0)];
let colors = vec![MyColor::from_rgb(0, 255, 0)];
let row =
DataRow::from_cells2_sized(RowId::new(), ent_path, frame3, 1, (color_instances, colors))
.unwrap();
Expand All @@ -397,7 +389,7 @@ fn invalidation_timeless() {

let query_time = [build_frame_nr(9999.into())];

let positions = vec![Position2D::new(1.0, 2.0), Position2D::new(3.0, 4.0)];
let positions = vec![MyPoint::new(1.0, 2.0), MyPoint::new(3.0, 4.0)];
let row =
DataRow::from_cells1_sized(RowId::new(), ent_path, timeless.clone(), 2, positions).unwrap();
store.insert_row(&row).unwrap();
Expand All @@ -406,7 +398,7 @@ fn invalidation_timeless() {
query_and_compare(&store, &query, &ent_path.into());

let color_instances = vec![InstanceKey::SPLAT];
let colors = vec![Color::from_rgb(255, 0, 0)];
let colors = vec![MyColor::from_rgb(255, 0, 0)];
let row = DataRow::from_cells2_sized(
RowId::new(),
ent_path,
Expand All @@ -421,7 +413,7 @@ fn invalidation_timeless() {
query_and_compare(&store, &query, &ent_path.into());

let color_instances = vec![InstanceKey::SPLAT];
let colors = vec![Color::from_rgb(0, 0, 255)];
let colors = vec![MyColor::from_rgb(0, 0, 255)];
let row = DataRow::from_cells2_sized(
RowId::new(),
ent_path,
Expand All @@ -444,7 +436,7 @@ fn query_and_compare(store: &DataStore, query: &LatestAtQuery, ent_path: &Entity
let mut uncached_instance_keys = Vec::new();
let mut uncached_positions = Vec::new();
let mut uncached_colors = Vec::new();
query_archetype_pov1_comp1::<Points2D, Position2D, Color, _>(
query_archetype_pov1_comp1::<MyPoints, MyPoint, MyColor, _>(
false, // cached?
store,
&query.clone().into(),
Expand All @@ -462,7 +454,7 @@ fn query_and_compare(store: &DataStore, query: &LatestAtQuery, ent_path: &Entity
let mut cached_instance_keys = Vec::new();
let mut cached_positions = Vec::new();
let mut cached_colors = Vec::new();
query_archetype_pov1_comp1::<Points2D, Position2D, Color, _>(
query_archetype_pov1_comp1::<MyPoints, MyPoint, MyColor, _>(
true, // cached?
store,
&query.clone().into(),
Expand All @@ -477,14 +469,14 @@ fn query_and_compare(store: &DataStore, query: &LatestAtQuery, ent_path: &Entity
.unwrap();

let (expected_data_time, expected) =
re_query::query_archetype::<Points2D>(store, query, ent_path).unwrap();
re_query::query_archetype::<MyPoints>(store, query, ent_path).unwrap();
let expected_instance_keys = expected.iter_instance_keys().collect_vec();
let expected_positions = expected
.iter_required_component::<Position2D>()
.iter_required_component::<MyPoint>()
.unwrap()
.collect_vec();
let expected_colors = expected
.iter_optional_component::<Color>()
.iter_optional_component::<MyColor>()
.unwrap()
.collect_vec();

Expand Down
Loading

0 comments on commit 2d39d88

Please sign in to comment.