Skip to content

Commit 12d26c8

Browse files
authored
Columnar APIs: autogenerate helpers for unit-length batches (#8775)
This makes the API far easier to use in the very common case where the caller wants to split all of their data in unit-length batches. I think it's worth the extra generated code. Notes: * The naming sucks. * I disabled columnar APIs entirely for all blueprint stuff. I don't see any reason to have all this code? ```diff let times = TimeColumn::new_sequence("step", 0..STEPS); let scalars = (0..STEPS).map(|step| (step as f64 / 10.0).sin()); rec.send_columns_v2( "scalars", [times], rerun::Scalar::update_fields() .with_many_scalar(scalars) - .columns(std::iter::repeat(1).take(STEPS as _))?, + .unary_columns()?, )?; ``` * Follow-up to #8753
1 parent 67df6b1 commit 12d26c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+591
-758
lines changed

crates/build/re_types_builder/src/codegen/rust/api.rs

+36-2
Original file line numberDiff line numberDiff line change
@@ -1944,7 +1944,7 @@ fn quote_builder_from_obj(reporter: &Reporter, objects: &Objects, obj: &Object)
19441944
}
19451945
});
19461946

1947-
let columnar_methods = obj.is_eager_rust_archetype().then(|| {
1947+
let columnar_methods = (obj.is_eager_rust_archetype() && obj.scope().is_none()).then(|| {
19481948
let columns_doc = unindent::unindent("\
19491949
Partitions the component data into multiple sub-batches.
19501950
@@ -1959,15 +1959,32 @@ fn quote_builder_from_obj(reporter: &Reporter, objects: &Objects, obj: &Object)
19591959
");
19601960
let columns_doc = quote_doc_lines(&columns_doc.lines().map(|l| l.to_owned()).collect_vec());
19611961

1962-
let has_indicator = obj.fqname.as_str() != "rerun.archetypes.Scalar";
1962+
let columns_unary_doc = unindent::unindent("\
1963+
Helper to partition the component data into unit-length sub-batches.
1964+
1965+
This is semantically similar to calling [`Self::columns`] with `std::iter::take(1).repeat(n)`,
1966+
where `n` is automatically guessed.
1967+
");
1968+
let columns_unary_doc = quote_doc_lines(&columns_unary_doc.lines().map(|l| l.to_owned()).collect_vec());
19631969

1970+
let has_indicator = obj.fqname.as_str() != "rerun.archetypes.Scalar";
19641971
let num_fields = required.iter().chain(optional.iter()).count();
1972+
19651973
let fields = required.iter().chain(optional.iter()).map(|field| {
19661974
let field_name = format_ident!("{}", field.name);
19671975
let clone = if num_fields == 1 && !has_indicator { quote!(.into_iter()) } else { quote!(.clone()) };
19681976
quote!(self.#field_name.map(|#field_name| #field_name.partitioned(_lengths #clone)).transpose()?)
19691977
});
19701978

1979+
let field_lengths = required.iter().chain(optional.iter()).map(|field| {
1980+
format_ident!("len_{}", field.name)
1981+
}).collect_vec();
1982+
let unary_fields = required.iter().chain(optional.iter()).map(|field| {
1983+
let field_name = format_ident!("{}", field.name);
1984+
let len_field_name = format_ident!("len_{}", field.name);
1985+
quote!(let #len_field_name = self.#field_name.as_ref().map(|b| b.array.len()))
1986+
});
1987+
19711988
let indicator_column = if !has_indicator {
19721989
// NOTE(#8768): Scalar indicators are extremely wasteful, and not actually used for anything.
19731990
quote!(None)
@@ -1989,6 +2006,23 @@ fn quote_builder_from_obj(reporter: &Reporter, objects: &Objects, obj: &Object)
19892006
let indicator_column = #indicator_column;
19902007
Ok(columns.into_iter().chain([indicator_column]).flatten())
19912008
}
2009+
2010+
#columns_unary_doc
2011+
#[inline]
2012+
pub fn columns_of_unit_batches(
2013+
self,
2014+
) -> SerializationResult<impl Iterator<Item = ::re_types_core::SerializedComponentColumn>>
2015+
{
2016+
#(#unary_fields);*;
2017+
2018+
let len = None
2019+
#(.or(#field_lengths))*
2020+
.unwrap_or(0);
2021+
2022+
// NOTE: This will return an error if the different batches have different lengths,
2023+
// which is fine.
2024+
self.columns(std::iter::repeat(1).take(len))
2025+
}
19922026
}
19932027
});
19942028

crates/store/re_types/src/archetypes/arrows2d.rs

+29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/store/re_types/src/archetypes/arrows3d.rs

+27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/store/re_types/src/archetypes/bar_chart.rs

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/store/re_types/src/archetypes/capsules3d.rs

+31
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/store/re_types/src/archetypes/depth_image.rs

+27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/store/re_types/src/archetypes/ellipsoids3d.rs

+33
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/store/re_types/src/archetypes/encoded_image.rs

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/store/re_types/src/archetypes/geo_line_strings.rs

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/store/re_types/src/archetypes/geo_points.rs

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/store/re_types/src/archetypes/graph_edges.rs

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)