@@ -18,7 +18,10 @@ pub struct InputColumn {
18
18
}
19
19
20
20
pub struct OutputColumn {
21
- pub entity_path : EntityPath ,
21
+ /// The target entity path for this column.
22
+ ///
23
+ /// If `None`, the entity path of the output column will be set to the matched entity path of the input column.
24
+ pub new_entity_path : Option < EntityPath > ,
22
25
pub component_descr : ComponentDescriptor ,
23
26
pub ops : Vec < Op > ,
24
27
// TODO(grtlr): It would be much nicer if static could be inferred from the output of the operations?
@@ -66,7 +69,7 @@ impl Op {
66
69
67
70
/// Ignores any input and returns a constant `ListArray`.
68
71
///
69
- /// Mostl commonly used with [`LensBuilder::add_static_output_column `].
72
+ /// Commonly used with [`LensBuilder::add_static_output_column_entity `].
70
73
/// When used in non-static columns this function will _not_ guarantee the correct amount of rows.
71
74
pub fn constant ( value : ListArray ) -> Self {
72
75
Self :: func ( move |_| Ok ( value. clone ( ) ) )
@@ -132,8 +135,13 @@ impl Lens {
132
135
133
136
let mut builders = ahash:: HashMap :: default ( ) ;
134
137
for output in & self . outputs {
138
+ let entity_path = output
139
+ . new_entity_path
140
+ . as_ref ( )
141
+ . unwrap_or ( chunk. entity_path ( ) ) ;
142
+
135
143
let components = builders
136
- . entry ( ( output . entity_path . clone ( ) , output. is_static ) )
144
+ . entry ( ( entity_path. clone ( ) , output. is_static ) )
137
145
. or_insert_with ( ChunkComponents :: default) ;
138
146
139
147
if components. contains_component ( & output. component_descr ) {
@@ -150,7 +158,7 @@ impl Lens {
150
158
re_log:: error!(
151
159
"Lens operation '{:?}' failed for output column '{}' on entity '{}': {err}" ,
152
160
op,
153
- output . entity_path,
161
+ entity_path,
154
162
output. component_descr. component
155
163
) ;
156
164
return vec ! [ ] ;
@@ -205,14 +213,35 @@ impl LensBuilder {
205
213
206
214
/// Can be used to define one or more output columns that are derived from the
207
215
/// component specified via [`Self::for_input_column`].
216
+ ///
217
+ /// The output column will live on the same entity path as the input column.
208
218
pub fn add_output_column (
219
+ mut self ,
220
+ component_descr : ComponentDescriptor ,
221
+ ops : impl IntoIterator < Item = Op > ,
222
+ ) -> Self {
223
+ let column = OutputColumn {
224
+ new_entity_path : None ,
225
+ component_descr,
226
+ ops : ops. into_iter ( ) . collect ( ) ,
227
+ is_static : false ,
228
+ } ;
229
+ self . 0 . outputs . push ( column) ;
230
+ self
231
+ }
232
+
233
+ /// Can be used to define one or more output columns that are derived from the
234
+ /// component specified via [`Self::for_input_column`].
235
+ ///
236
+ /// The output column will live on the same entity path as the input column.
237
+ pub fn add_output_column_entity (
209
238
mut self ,
210
239
entity_path : impl Into < EntityPath > ,
211
240
component_descr : ComponentDescriptor ,
212
241
ops : impl IntoIterator < Item = Op > ,
213
242
) -> Self {
214
243
let column = OutputColumn {
215
- entity_path : entity_path. into ( ) ,
244
+ new_entity_path : Some ( entity_path. into ( ) ) ,
216
245
component_descr,
217
246
ops : ops. into_iter ( ) . collect ( ) ,
218
247
is_static : false ,
@@ -224,15 +253,19 @@ impl LensBuilder {
224
253
/// Can be used to define one or more static output columns that are derived from the
225
254
/// component specified via [`Self::for_input_column`].
226
255
///
256
+ /// The output column will live on the same entity path as the input column.
257
+ ///
227
258
/// In most cases, static columns should have a single row only.
228
- pub fn add_static_output_column (
259
+ // TODO(grtlr): We don't provide a non-entity version of this method, because it is
260
+ // likely to change again anyway.
261
+ pub fn add_static_output_column_entity (
229
262
mut self ,
230
263
entity_path : impl Into < EntityPath > ,
231
264
component_descr : ComponentDescriptor ,
232
265
ops : impl IntoIterator < Item = Op > ,
233
266
) -> Self {
234
267
let column = OutputColumn {
235
- entity_path : entity_path. into ( ) ,
268
+ new_entity_path : Some ( entity_path. into ( ) ) ,
236
269
component_descr,
237
270
ops : ops. into_iter ( ) . collect ( ) ,
238
271
is_static : true ,
@@ -449,7 +482,7 @@ mod test {
449
482
450
483
let destructure =
451
484
Lens :: for_input_column ( EntityPathFilter :: parse_forgiving ( "nullability" ) , "structs" )
452
- . add_output_column (
485
+ . add_output_column_entity (
453
486
"nullability/a" ,
454
487
Scalars :: descriptor_scalars ( ) ,
455
488
[ Op :: access_field ( "a" ) , Op :: cast ( DataType :: Float64 ) ] ,
@@ -474,7 +507,7 @@ mod test {
474
507
475
508
let destructure =
476
509
Lens :: for_input_column ( EntityPathFilter :: parse_forgiving ( "nullability" ) , "structs" )
477
- . add_output_column (
510
+ . add_output_column_entity (
478
511
"nullability/b" ,
479
512
Scalars :: descriptor_scalars ( ) ,
480
513
[ Op :: access_field ( "b" ) ] ,
@@ -517,13 +550,8 @@ mod test {
517
550
518
551
let count =
519
552
Lens :: for_input_column ( EntityPathFilter :: parse_forgiving ( "nullability" ) , "strings" )
553
+ . add_output_column ( ComponentDescriptor :: partial ( "counts" ) , [ Op :: func ( count_fn) ] )
520
554
. add_output_column (
521
- "nullability/b_count" ,
522
- ComponentDescriptor :: partial ( "counts" ) ,
523
- [ Op :: func ( count_fn) ] ,
524
- )
525
- . add_output_column (
526
- "nullability/b_count" ,
527
555
ComponentDescriptor :: partial ( "original" ) ,
528
556
[ ] , // no operations
529
557
)
@@ -558,12 +586,12 @@ mod test {
558
586
559
587
let static_lens =
560
588
Lens :: for_input_column ( EntityPathFilter :: parse_forgiving ( "nullability" ) , "strings" )
561
- . add_static_output_column (
589
+ . add_static_output_column_entity (
562
590
"nullability/static" ,
563
591
ComponentDescriptor :: partial ( "static_metadata_a" ) ,
564
592
[ Op :: constant ( metadata_builder_a. finish ( ) ) ] ,
565
593
)
566
- . add_static_output_column (
594
+ . add_static_output_column_entity (
567
595
"nullability/static" ,
568
596
ComponentDescriptor :: partial ( "static_metadata_b" ) ,
569
597
[ Op :: constant ( metadata_builder_b. finish ( ) ) ] ,
0 commit comments