re_redap_tests 0.31.2

Official test suite for the Rerun Data Protocol
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
#![expect(clippy::unwrap_used)]

use super::common::{
    DataSourcesDefinition, LayerDefinition, RerunCloudServiceExt as _, entry_name,
};
use crate::tests::common::concat_record_batches;
use crate::{FieldsTestExt as _, RecordBatchTestExt as _, SchemaTestExt as _};
use arrow::array::{RecordBatch, StringArray};
use arrow::datatypes::Schema;
use futures::TryStreamExt as _;
use itertools::Itertools as _;
use re_arrow_util::{ArrowArrayDowncastRef as _, RecordBatchExt as _};
use re_protos::cloud::v1alpha1::ext::{LayerRegistrationStatus, QueryDatasetRequest};
use re_protos::cloud::v1alpha1::rerun_cloud_service_server::RerunCloudService;
use re_protos::cloud::v1alpha1::{
    GetDatasetManifestSchemaRequest, GetSegmentTableSchemaRequest, QueryDatasetResponse,
    ReadDatasetEntryRequest, ScanDatasetManifestRequest, ScanDatasetManifestResponse,
    ScanSegmentTableRequest, ScanSegmentTableResponse,
};
use re_protos::headers::RerunHeadersInjectorExt as _;

pub async fn unregister_simple(service: impl RerunCloudService) {
    let data_sources_def = DataSourcesDefinition::new_with_tuid_prefix(
        1,
        [
            LayerDefinition::simple("my_segment_id1", &["my/entity", "my/other/entity"]),
            LayerDefinition::simple("my_segment_id2", &["my/entity"]),
            LayerDefinition::simple(
                "my_segment_id3",
                &["my/entity", "another/one", "yet/another/one"],
            ),
        ],
    );

    let dataset_name = "my_dataset1";
    service.create_dataset_entry_with_name(dataset_name).await;
    service
        .register_with_dataset_name_blocking(dataset_name, data_sources_def.to_data_sources())
        .await;
    let dataset_updated_at_1 = get_dataset_updated_at_nanos(&service, dataset_name).await;
    {
        let snapshot_name = "simple_1_register_all";
        scan_segment_table_and_snapshot(&service, dataset_name, snapshot_name).await;
        scan_dataset_manifest_and_snapshot(&service, dataset_name, snapshot_name).await;
    }

    let removed = service
        .unregister_from_dataset_name(dataset_name, &["my_segment_id2"], &["base"])
        .await;
    let dataset_updated_at_2 = get_dataset_updated_at_nanos(&service, dataset_name).await;
    {
        let snapshot_name = "simple_2_remove_segment_id2";
        snapshot_response(
            &service,
            dataset_name,
            snapshot_name,
            removed.expect("removal should succeed"),
        )
        .await;
        scan_segment_table_and_snapshot(&service, dataset_name, snapshot_name).await;
        scan_dataset_manifest_and_snapshot(&service, dataset_name, snapshot_name).await;
    }

    let removed = service
        .unregister_from_dataset_name(
            dataset_name,
            &["my_segment_id1", "my_segment_id3"],
            &["base"],
        )
        .await;
    let dataset_updated_at_3 = get_dataset_updated_at_nanos(&service, dataset_name).await;
    {
        let snapshot_name = "simple_3_remove_remaining_segments";
        snapshot_response(
            &service,
            dataset_name,
            snapshot_name,
            removed.expect("removal should succeed"),
        )
        .await;
        scan_segment_table_and_snapshot(&service, dataset_name, snapshot_name).await;
        scan_dataset_manifest_and_snapshot(&service, dataset_name, snapshot_name).await;
    }

    // Make sure re-registering on top of an unregistered segment doesn't do anything weird.
    service
        .register_with_dataset_name_blocking(dataset_name, data_sources_def.to_data_sources())
        .await;
    let dataset_updated_at_4 = get_dataset_updated_at_nanos(&service, dataset_name).await;
    {
        let snapshot_name = "simple_4_reregister_all";
        scan_segment_table_and_snapshot(&service, dataset_name, snapshot_name).await;
        scan_dataset_manifest_and_snapshot(&service, dataset_name, snapshot_name).await;
    }

    assert!(
        dataset_updated_at_1 < dataset_updated_at_2,
        "Timestamp should be updated after adding or removing a layer."
    );
    assert!(
        dataset_updated_at_2 < dataset_updated_at_3,
        "Timestamp should be updated after adding or removing a layer."
    );
    assert!(
        dataset_updated_at_3 < dataset_updated_at_4,
        "Timestamp should be updated after adding or removing a layer."
    );
}

pub async fn unregister_products(service: impl RerunCloudService) {
    let data_sources_def = DataSourcesDefinition::new_with_tuid_prefix(
        1,
        [
            LayerDefinition::simple("my_segment_id1", &["my/entity"]).layer_name("A"), //
            LayerDefinition::simple("my_segment_id1", &["my/entity"]).layer_name("B"),
            LayerDefinition::simple("my_segment_id1", &["my/entity"]).layer_name("C"),
            LayerDefinition::simple("my_segment_id1", &["my/entity"]).layer_name("D"),
            //
            LayerDefinition::simple("my_segment_id2", &["my/entity"]).layer_name("A"), //
            LayerDefinition::simple("my_segment_id2", &["my/entity"]).layer_name("B"),
            LayerDefinition::simple("my_segment_id2", &["my/entity"]).layer_name("C"),
            LayerDefinition::simple("my_segment_id2", &["my/entity"]).layer_name("D"),
            //
            LayerDefinition::simple("my_segment_id3", &["my/entity"]).layer_name("A"), //
            LayerDefinition::simple("my_segment_id3", &["my/entity"]).layer_name("B"),
            LayerDefinition::simple("my_segment_id3", &["my/entity"]).layer_name("C"),
            LayerDefinition::simple("my_segment_id3", &["my/entity"]).layer_name("D"),
        ],
    );

    let dataset_name = "my_dataset1";
    service.create_dataset_entry_with_name(dataset_name).await;
    service
        .register_with_dataset_name_blocking(dataset_name, data_sources_def.to_data_sources())
        .await;
    {
        let snapshot_name = "products_1_register_all";
        scan_segment_table_and_snapshot(&service, dataset_name, snapshot_name).await;
        scan_dataset_manifest_and_snapshot(&service, dataset_name, snapshot_name).await;
    }

    let removed = service
        .unregister_from_dataset_name(
            dataset_name,
            &["my_segment_id1", "my_segment_id3"],
            &["B", "D"],
        )
        .await;
    {
        let snapshot_name = "products_2_remove_layers_BD_for_segments_13";
        snapshot_response(
            &service,
            dataset_name,
            snapshot_name,
            removed.expect("removal should succeed"),
        )
        .await;
        scan_segment_table_and_snapshot(&service, dataset_name, snapshot_name).await;
        scan_dataset_manifest_and_snapshot(&service, dataset_name, snapshot_name).await;
    }

    let removed = service
        .unregister_from_dataset_name(dataset_name, &[], &["B", "D"])
        .await;
    {
        let snapshot_name = "products_3_remove_layers_BD_for_all_segments";
        snapshot_response(
            &service,
            dataset_name,
            snapshot_name,
            removed.expect("removal should succeed"),
        )
        .await;
        scan_segment_table_and_snapshot(&service, dataset_name, snapshot_name).await;
        scan_dataset_manifest_and_snapshot(&service, dataset_name, snapshot_name).await;
    }

    let removed = service
        .unregister_from_dataset_name(dataset_name, &["my_segment_id2", "my_segment_id3"], &[])
        .await;
    {
        let snapshot_name = "products_4_remove_all_layers_for_segments_23";
        snapshot_response(
            &service,
            dataset_name,
            snapshot_name,
            removed.expect("removal should succeed"),
        )
        .await;
        scan_segment_table_and_snapshot(&service, dataset_name, snapshot_name).await;
        scan_dataset_manifest_and_snapshot(&service, dataset_name, snapshot_name).await;
    }
}

pub async fn unregister_missing_dataset(service: impl RerunCloudService) {
    let dataset_name = "my_dataset_thats_not_there";

    let err = service
        .unregister_from_dataset_name(dataset_name, &["my_segment"], &[])
        .await
        .unwrap_err();
    assert_eq!(tonic::Code::NotFound, err.code());
}

pub async fn unregister_missing_segment(service: impl RerunCloudService) {
    let data_sources_def = DataSourcesDefinition::new_with_tuid_prefix(
        1,
        [LayerDefinition::simple(
            "my_segment_id1",
            &["my/entity", "my/other/entity"],
        )],
    );

    let dataset_name = "my_dataset1";
    service.create_dataset_entry_with_name(dataset_name).await;
    service
        .register_with_dataset_name_blocking(dataset_name, data_sources_def.to_data_sources())
        .await;

    let removed = service
        .unregister_from_dataset_name(dataset_name, &["some_segment_thats_not_there"], &[])
        .await;
    {
        let snapshot_name = "missing_1_should_be_empty";
        snapshot_response(
            &service,
            dataset_name,
            snapshot_name,
            removed.expect("removal should succeed"),
        )
        .await;
    }
}

pub async fn unregister_invalid_args(service: impl RerunCloudService) {
    {
        let dataset_name = "my_dataset_thats_not_there";

        let err = service
            .unregister_from_dataset_name(dataset_name, &[], &[])
            .await
            .unwrap_err();
        assert_eq!(tonic::Code::NotFound, err.code());
    }

    {
        let data_sources_def = DataSourcesDefinition::new_with_tuid_prefix(
            1,
            [LayerDefinition::simple(
                "my_segment_id1",
                &["my/entity", "my/other/entity"],
            )],
        );

        let dataset_name = "my_dataset1";
        service.create_dataset_entry_with_name(dataset_name).await;
        service
            .register_with_dataset_name_blocking(dataset_name, data_sources_def.to_data_sources())
            .await;

        let err = service
            .unregister_from_dataset_name(dataset_name, &[], &[])
            .await
            .unwrap_err();
        assert_eq!(tonic::Code::InvalidArgument, err.code());
    }
}

// Make sure we cannot find any data when the `status=deleted`.
pub async fn unregister_then_query(service: impl RerunCloudService) {
    let data_sources_def = DataSourcesDefinition::new_with_tuid_prefix(
        1,
        [
            LayerDefinition::simple("my_segment_id", &["my/entity", "my/other/entity"]), //
        ],
    );

    let dataset_name = "my_dataset1";
    service.create_dataset_entry_with_name(dataset_name).await;
    service
        .register_with_dataset_name_blocking(dataset_name, data_sources_def.to_data_sources())
        .await;

    query_dataset_snapshot(
        &service,
        QueryDatasetRequest::default(),
        dataset_name,
        "unregister_then_query_1_added",
    )
    .await;

    service
        .unregister_from_dataset_name(dataset_name, &["my_segment_id"], &[])
        .await
        .unwrap();

    query_dataset_snapshot(
        &service,
        QueryDatasetRequest::default(),
        dataset_name,
        "unregister_then_query_2_removed",
    )
    .await;
}

// ---

async fn scan_segment_table_and_snapshot(
    service: &impl RerunCloudService,
    dataset_name: &str,
    snapshot_name: &str,
) -> RecordBatch {
    let responses: Vec<_> = service
        .scan_segment_table(
            tonic::Request::new(ScanSegmentTableRequest {
                columns: vec![], // all of them
            })
            .with_entry_name(entry_name(dataset_name))
            .unwrap(),
        )
        .await
        .unwrap()
        .into_inner()
        .try_collect()
        .await
        .unwrap();

    let batches: Vec<RecordBatch> = responses
        .into_iter()
        .map(|resp| resp.data.unwrap().try_into().unwrap())
        .collect_vec();

    let batch = arrow::compute::concat_batches(
        batches
            .first()
            .expect("there should be at least one batch")
            .schema_ref(),
        &batches,
    )
    .unwrap();

    // check that the _advertised_ schema is consistent with the actual data.
    let alleged_schema: Schema = service
        .get_segment_table_schema(
            tonic::Request::new(GetSegmentTableSchemaRequest {})
                .with_entry_name(entry_name(dataset_name))
                .unwrap(),
        )
        .await
        .unwrap()
        .into_inner()
        .schema
        .unwrap()
        .try_into()
        .unwrap();

    // Note: we check fields only because some schema-level sorbet metadata is injected in one of
    // the paths and not the other. Anyway, that's what matters.
    assert_eq!(
        alleged_schema.fields(),
        batch.schema_ref().fields(),
        "The actual schema is not consistent with the schema advertised by \
        `get_segment_table_schema`.\n\nActual:\n{}\n\nAlleged:\n{}\n",
        batch.schema().format_snapshot(),
        alleged_schema.format_snapshot(),
    );

    let required_fields = ScanSegmentTableResponse::fields();
    assert!(
        batch.schema().fields().contains_unordered(&required_fields),
        "the schema should contain all the required fields, but it doesn't",
    );

    let unstable_column_names = vec![
        ScanSegmentTableResponse::FIELD_STORAGE_URLS,
        ScanSegmentTableResponse::FIELD_SIZE_BYTES,
        ScanSegmentTableResponse::FIELD_LAST_UPDATED_AT,
    ];
    let filtered_batch = batch
        .remove_columns(&unstable_column_names)
        .auto_sort_rows()
        .unwrap()
        .sort_property_columns()
        .sort_index_columns();

    insta::assert_snapshot!(
        format!("{snapshot_name}_segments_schema"),
        filter_out_index_ranges(batch.clone()).format_schema_snapshot()
    );
    insta::assert_snapshot!(
        format!("{snapshot_name}_segments_data"),
        filter_out_index_ranges(filtered_batch.clone()).format_snapshot(false)
    );

    batch
}

async fn scan_dataset_manifest_and_snapshot(
    service: &impl RerunCloudService,
    dataset_name: &str,
    snapshot_name: &str,
) -> RecordBatch {
    let responses: Vec<_> = service
        .scan_dataset_manifest(
            tonic::Request::new(ScanDatasetManifestRequest {
                columns: vec![], // all of them
            })
            .with_entry_name(entry_name(dataset_name))
            .unwrap(),
        )
        .await
        .unwrap()
        .into_inner()
        .try_collect()
        .await
        .unwrap();

    let batches: Vec<RecordBatch> = responses
        .into_iter()
        .map(|resp| resp.data.unwrap().try_into().unwrap())
        .collect_vec();

    let batch = arrow::compute::concat_batches(
        batches
            .first()
            .expect("there should be at least one batch")
            .schema_ref(),
        &batches,
    )
    .unwrap();

    // check that the _advertised_ schema is consistent with the actual data.
    let alleged_schema: Schema = service
        .get_dataset_manifest_schema(
            tonic::Request::new(GetDatasetManifestSchemaRequest {})
                .with_entry_name(entry_name(dataset_name))
                .unwrap(),
        )
        .await
        .unwrap()
        .into_inner()
        .schema
        .unwrap()
        .try_into()
        .unwrap();

    // Note: we check fields only because some schema-level sorbet metadata is injected in one of
    // the paths and not the other. Anyway, that's what matters.
    assert_eq!(
        alleged_schema.fields(),
        batch.schema_ref().fields(),
        "The actual schema is not consistent with the schema advertised by \
        `get_dataset_manifest_schema`.\n\nActual:\n{}\n\nAlleged:\n{}\n",
        batch.schema().format_snapshot(),
        alleged_schema.format_snapshot(),
    );

    let required_fields = ScanDatasetManifestResponse::fields();
    assert!(
        batch.schema().fields().contains_unordered(&required_fields),
        "the schema should contain all the required fields, but it doesn't",
    );

    let unstable_column_names = vec![
        // implementation-dependent
        ScanDatasetManifestResponse::FIELD_STORAGE_URL,
        ScanDatasetManifestResponse::FIELD_SIZE_BYTES,
        // unstable
        ScanDatasetManifestResponse::FIELD_LAST_UPDATED_AT,
        ScanDatasetManifestResponse::FIELD_REGISTRATION_TIME,
    ];
    let filtered_batch = batch
        .remove_columns(&unstable_column_names)
        .auto_sort_rows()
        .unwrap()
        .sort_property_columns();

    // For the comparison to make sense across the OSS and enterprise servers, we need to filter
    // out rows where `status=deleted`, since OSS doesn't keep track of removed segments/layers.
    let filtered_batch = {
        let col_status = filtered_batch
            .column_by_name(ScanDatasetManifestResponse::FIELD_REGISTRATION_STATUS)
            .unwrap();
        let col_status = col_status.downcast_array_ref::<StringArray>().unwrap();

        let mask = col_status
            .iter()
            .map(|s| s != Some(LayerRegistrationStatus::Deleted.as_str()))
            .collect_vec();

        arrow::compute::filter_record_batch(&filtered_batch, &mask.into()).unwrap()
    };

    insta::assert_snapshot!(
        format!("{snapshot_name}_manifest_schema"),
        batch.format_schema_snapshot()
    );
    insta::assert_snapshot!(
        format!("{snapshot_name}_manifest_data"),
        filtered_batch.format_snapshot(false)
    );

    batch
}

async fn snapshot_response(
    service: &impl RerunCloudService,
    dataset_name: &str,
    snapshot_name: &str,
    batch: RecordBatch,
) {
    // check that the _advertised_ schema is consistent with the actual data.
    let alleged_schema: Schema = service
        .get_dataset_manifest_schema(
            tonic::Request::new(GetDatasetManifestSchemaRequest {})
                .with_entry_name(entry_name(dataset_name))
                .unwrap(),
        )
        .await
        .unwrap()
        .into_inner()
        .schema
        .unwrap()
        .try_into()
        .unwrap();

    // Note: we check fields only because some schema-level sorbet metadata is injected in one of
    // the paths and not the other. Anyway, that's what matters.
    assert_eq!(
        alleged_schema.fields(),
        batch.schema_ref().fields(),
        "The actual schema is not consistent with the schema advertised by \
        `get_dataset_manifest_schema`.\n\nActual:\n{}\n\nAlleged:\n{}\n",
        batch.schema().format_snapshot(),
        alleged_schema.format_snapshot(),
    );

    let required_fields = ScanDatasetManifestResponse::fields();
    assert!(
        batch.schema().fields().contains_unordered(&required_fields),
        "the schema should contain all the required fields, but it doesn't",
    );

    let unstable_column_names = vec![
        // implementation-dependent
        ScanDatasetManifestResponse::FIELD_STORAGE_URL,
        ScanDatasetManifestResponse::FIELD_SIZE_BYTES,
        // unstable
        ScanDatasetManifestResponse::FIELD_LAST_UPDATED_AT,
        ScanDatasetManifestResponse::FIELD_REGISTRATION_TIME,
    ];
    let filtered_batch = batch
        .remove_columns(&unstable_column_names)
        .auto_sort_rows()
        .unwrap()
        .sort_property_columns();

    // For the comparison to make sense across the OSS and enterprise servers, we need to filter
    // out rows where `status=deleted`, since OSS doesn't keep track of removed segments/layers.
    let filtered_batch = {
        let col_status = filtered_batch
            .column_by_name(ScanDatasetManifestResponse::FIELD_REGISTRATION_STATUS)
            .unwrap();
        let col_status = col_status.downcast_array_ref::<StringArray>().unwrap();

        let mask = col_status
            .iter()
            .map(|s| s != Some(LayerRegistrationStatus::Deleted.as_str()))
            .collect_vec();

        arrow::compute::filter_record_batch(&filtered_batch, &mask.into()).unwrap()
    };

    insta::assert_snapshot!(
        format!("{snapshot_name}_response_schema"),
        batch.format_schema_snapshot()
    );
    insta::assert_snapshot!(
        format!("{snapshot_name}_response_data"),
        filtered_batch.format_snapshot(false)
    );
}

async fn query_dataset_snapshot(
    service: &impl RerunCloudService,
    query_dataset_request: QueryDatasetRequest,
    dataset_name: &str,
    snapshot_name: &str,
) {
    use futures::StreamExt as _;

    let chunk_info = service
        .query_dataset(
            tonic::Request::new(query_dataset_request.into())
                .with_entry_name(entry_name(dataset_name))
                .unwrap(),
        )
        .await
        .unwrap()
        .into_inner()
        .flat_map(|resp| futures::stream::iter(resp.unwrap().data))
        .map(|dfp| dfp.try_into().unwrap())
        .collect::<Vec<_>>()
        .await;

    let merged_chunk_info = concat_record_batches(&chunk_info);

    // these are the only columns guaranteed to be returned by `query_dataset`
    let required_field = QueryDatasetResponse::fields();

    assert!(
        merged_chunk_info
            .schema()
            .fields()
            .contains_unordered(&required_field),
        "query dataset must return all guaranteed fields\nExpected: {:#?}\nGot: {:#?}",
        required_field,
        merged_chunk_info.schema().fields(),
    );

    let required_column_names = required_field
        .iter()
        .map(|f| f.name().as_str())
        .collect::<Vec<_>>();
    let required_chunk_info = merged_chunk_info
        .project_columns(required_column_names.iter().copied())
        .unwrap();

    insta::assert_snapshot!(
        format!("{snapshot_name}_schema"),
        required_chunk_info.format_schema_snapshot()
    );

    // these columns are not stable, so we cannot snapshot them
    let filtered_chunk_info = required_chunk_info
        .remove_columns(&[
            QueryDatasetResponse::FIELD_CHUNK_KEY,
            QueryDatasetResponse::FIELD_CHUNK_BYTE_LENGTH,
        ])
        .auto_sort_rows()
        .unwrap();

    insta::assert_snapshot!(
        format!("{snapshot_name}_data"),
        filtered_chunk_info.format_snapshot(false)
    );
}

/// Remove columns such `frame:start`, `log_time:end`, etc.
///
/// There is a fundamental discrepancy between how OSS and DPF handle deleted segments/layers:
/// * OSS actually deletes things and doesn't keep track of any kind of history.
/// * DPF keeps segments around but marks them with a tombstone.
///
/// On its own this is fine, but this interacts with yet another discrepancy: how OSS vs. DPF
/// compute schemas and such.
/// * OSS computes schemas just-in-time, based on whatever data exists at the moment of the call.
/// * DPF materializes all schemas.
///
/// All of this results in OSS dropping index ranges where the last layer using those indexes has
/// been removed, while they will still be there in DPF, as empty columns.
///
/// For now, we just accept it and move on.
fn filter_out_index_ranges(batch: RecordBatch) -> RecordBatch {
    batch
        .filter_columns_by(|f| f.metadata().get("rerun:index_marker").is_none())
        .unwrap()
}

async fn get_dataset_updated_at_nanos(service: &impl RerunCloudService, dataset_name: &str) -> i64 {
    service
        .read_dataset_entry(
            tonic::Request::new(ReadDatasetEntryRequest {})
                .with_entry_name(entry_name(dataset_name))
                .unwrap(),
        )
        .await
        .unwrap()
        .into_inner()
        .dataset
        .unwrap()
        .details
        .as_ref()
        .unwrap()
        .updated_at
        .as_ref()
        .map(|ts| ts.seconds * 1_000_000_000 + ts.nanos as i64)
        .unwrap()
}