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

Fix bug when joining cleared optional components #3726

Merged
merged 4 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
13 changes: 12 additions & 1 deletion crates/re_query/src/archetype_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,9 @@ impl<A: Archetype> ArchetypeView<A> {

let component = self.components.get(&C::name());

if let Some(component) = component {
let is_empty = component.map_or(true, |c| c.is_empty());

if let (Some(component), false) = (component, is_empty) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please motivate this with a comment, i.e. why only non-empty components?

And does the code handle splat components (length=1) correctly?

// NOTE(1): Autogenerated instance keys are interned behind datacells.
// If two or more rows in the store share the same keys, then they will share
// also the same cells.
Expand All @@ -357,6 +359,15 @@ impl<A: Archetype> ArchetypeView<A> {
// - If the data isn't the same, the cost of the comparison will be dwarfed by the cost
// of the join anyway.
if self.required_comp().instance_keys == component.instance_keys {
// This fast iterator is assumed to match the length of the primary component
// We shouldn't hit this if since the store should enforce matched lengths for
// non-empty components, and the outer if-guard should keep us from reaching this
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, I don't think this is true for splats, e.g. Points3D(positions=[a,b,c,d], colors=[rgba])

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splats are currently split into their own rows. See: #1893 -- adding a TODO linking to that issue though.

// in the case of an empty component.
debug_assert!(
self.required_comp().instance_keys.num_instances()
== component.values.num_instances()
);

// NOTE: A component instance cannot be optional in itself, and if we're on this
// path then we know for a fact that both batches can be intersected 1-to-1.
// Therefore there cannot be any null values, therefore we can go through the fast
Expand Down
39 changes: 39 additions & 0 deletions crates/re_query/tests/archetype_visit_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,42 @@ fn joint_visit() {
assert_eq!(positions, positions_out);
assert_eq!(expected_colors, colors_out);
}

#[test]
fn joint_visit_with_empty() {
let positions = vec![
Position2D::new(1.0, 2.0), //
Position2D::new(3.0, 4.0),
Position2D::new(5.0, 6.0),
Position2D::new(7.0, 8.0),
Position2D::new(9.0, 10.0),
];

let shared_ids = InstanceKey::from_iter(0..5);

let colors: Vec<Color> = vec![];

let positions_comp =
ComponentWithInstances::from_native(shared_ids.clone(), positions.clone()).unwrap();
let colors_comp = ComponentWithInstances::from_native(shared_ids, colors).unwrap();
jleibs marked this conversation as resolved.
Show resolved Hide resolved

let arch_view =
ArchetypeView::<Points2D>::from_components(RowId::ZERO, [positions_comp, colors_comp]);

let mut positions_out = Vec::<Position2D>::new();
let mut colors_out = Vec::<Option<Color>>::new();

itertools::izip!(
arch_view.iter_required_component::<Position2D>().unwrap(),
arch_view.iter_optional_component::<Color>().unwrap()
)
.for_each(|(point, color)| {
positions_out.push(point);
colors_out.push(color);
});
jleibs marked this conversation as resolved.
Show resolved Hide resolved

let expected_colors = vec![None, None, None, None, None];

assert_eq!(positions, positions_out);
assert_eq!(expected_colors, colors_out);
}
Loading