Skip to content

Commit e547ef4

Browse files
committed
port re_query's range test suite 1:1
1 parent 6383589 commit e547ef4

File tree

2 files changed

+426
-46
lines changed

2 files changed

+426
-46
lines changed

crates/re_query_cache/tests/latest_at.rs

+38-46
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
use itertools::Itertools as _;
66

77
use re_data_store::{DataStore, LatestAtQuery};
8-
use re_log_types::{build_frame_nr, DataRow, EntityPath, RowId, TimePoint};
9-
use re_query_cache::query_archetype_pov1_comp1;
10-
use re_types::{
11-
archetypes::Points2D,
12-
components::{Color, InstanceKey, Position2D},
8+
use re_log_types::{
9+
build_frame_nr,
10+
example_components::{MyColor, MyPoint, MyPoints},
11+
DataRow, EntityPath, RowId, TimePoint,
1312
};
14-
use re_types_core::Loggable as _;
13+
use re_query_cache::query_archetype_pov1_comp1;
14+
use re_types_core::{components::InstanceKey, Loggable as _};
1515

1616
// ---
1717

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

254249
// Modify the PoV component
255-
let positions = vec![
256-
Position2D::new(1000.0, 2000.0),
257-
Position2D::new(3000.0, 4000.0),
258-
];
250+
let positions = vec![MyPoint::new(1000.0, 2000.0), MyPoint::new(3000.0, 4000.0)];
259251
let row = DataRow::from_cells1_sized(
260252
RowId::new(),
261253
ent_path,
@@ -269,7 +261,7 @@ fn invalidation() {
269261
query_and_compare(&store, &query, &ent_path.into());
270262

271263
// Modify the optional component
272-
let colors = vec![Color::from_rgb(16, 17, 18)];
264+
let colors = vec![MyColor::from_rgb(16, 17, 18)];
273265
let row =
274266
DataRow::from_cells1_sized(RowId::new(), ent_path, future_data_timepoint, 1, colors)
275267
.unwrap();
@@ -312,19 +304,19 @@ fn invalidation() {
312304
// # Expected: points=[[1,2,3]] colors=[]
313305
//
314306
// rr.set_time(2)
315-
// rr.log_components("points", rr.components.Color(0xFF0000))
307+
// rr.log_components("points", rr.components.MyColor(0xFF0000))
316308
//
317309
// # Do second query here: LatestAt(+inf)
318310
// # Expected: points=[[1,2,3]] colors=[0xFF0000]
319311
//
320312
// rr.set_time(3)
321-
// rr.log_components("points", rr.components.Color(0x0000FF))
313+
// rr.log_components("points", rr.components.MyColor(0x0000FF))
322314
//
323315
// # Do third query here: LatestAt(+inf)
324316
// # Expected: points=[[1,2,3]] colors=[0x0000FF]
325317
//
326318
// rr.set_time(3)
327-
// rr.log_components("points", rr.components.Color(0x00FF00))
319+
// rr.log_components("points", rr.components.MyColor(0x00FF00))
328320
//
329321
// # Do fourth query here: LatestAt(+inf)
330322
// # Expected: points=[[1,2,3]] colors=[0x00FF00]
@@ -345,15 +337,15 @@ fn invalidation_of_future_optionals() {
345337

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

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

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

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

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

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

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

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

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

423415
let color_instances = vec![InstanceKey::SPLAT];
424-
let colors = vec![Color::from_rgb(0, 0, 255)];
416+
let colors = vec![MyColor::from_rgb(0, 0, 255)];
425417
let row = DataRow::from_cells2_sized(
426418
RowId::new(),
427419
ent_path,
@@ -444,7 +436,7 @@ fn query_and_compare(store: &DataStore, query: &LatestAtQuery, ent_path: &Entity
444436
let mut uncached_instance_keys = Vec::new();
445437
let mut uncached_positions = Vec::new();
446438
let mut uncached_colors = Vec::new();
447-
query_archetype_pov1_comp1::<Points2D, Position2D, Color, _>(
439+
query_archetype_pov1_comp1::<MyPoints, MyPoint, MyColor, _>(
448440
false, // cached?
449441
store,
450442
&query.clone().into(),
@@ -462,7 +454,7 @@ fn query_and_compare(store: &DataStore, query: &LatestAtQuery, ent_path: &Entity
462454
let mut cached_instance_keys = Vec::new();
463455
let mut cached_positions = Vec::new();
464456
let mut cached_colors = Vec::new();
465-
query_archetype_pov1_comp1::<Points2D, Position2D, Color, _>(
457+
query_archetype_pov1_comp1::<MyPoints, MyPoint, MyColor, _>(
466458
true, // cached?
467459
store,
468460
&query.clone().into(),
@@ -477,14 +469,14 @@ fn query_and_compare(store: &DataStore, query: &LatestAtQuery, ent_path: &Entity
477469
.unwrap();
478470

479471
let (expected_data_time, expected) =
480-
re_query::query_archetype::<Points2D>(store, query, ent_path).unwrap();
472+
re_query::query_archetype::<MyPoints>(store, query, ent_path).unwrap();
481473
let expected_instance_keys = expected.iter_instance_keys().collect_vec();
482474
let expected_positions = expected
483-
.iter_required_component::<Position2D>()
475+
.iter_required_component::<MyPoint>()
484476
.unwrap()
485477
.collect_vec();
486478
let expected_colors = expected
487-
.iter_optional_component::<Color>()
479+
.iter_optional_component::<MyColor>()
488480
.unwrap()
489481
.collect_vec();
490482

0 commit comments

Comments
 (0)