From bc4f4ab109c545e79b3761b7b63eb9fea335b47b Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 6 Jan 2025 15:23:48 +0100 Subject: [PATCH] Don't crash --- .../src/display_record_batch.rs | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/crates/viewer/re_view_dataframe/src/display_record_batch.rs b/crates/viewer/re_view_dataframe/src/display_record_batch.rs index ef25a270d2b23..7de6e978ab290 100644 --- a/crates/viewer/re_view_dataframe/src/display_record_batch.rs +++ b/crates/viewer/re_view_dataframe/src/display_record_batch.rs @@ -183,32 +183,31 @@ impl DisplayColumn { ) -> Result { fn int64_from_nanoseconds( duration_array: &ArrowTimestampNanosecondArray, - ) -> ArrowInt64Array { + ) -> Option { let data = duration_array.to_data(); - let buffer = data.buffers()[0].clone(); - let int64_data = arrow::array::ArrayData::builder(arrow::datatypes::DataType::Int64) + let buffer = data.buffers().first()?.clone(); + arrow::array::ArrayData::builder(arrow::datatypes::DataType::Int64) .len(duration_array.len()) .add_buffer(buffer) .build() - .expect("Nanonseconds should be represented as i64"); - ArrowInt64Array::from(int64_data) + .ok() + .map(ArrowInt64Array::from) } match column_descriptor { ColumnDescriptor::Time(desc) => { let timeline = desc.timeline; - let time_data_result = match timeline.typ() { - TimeType::Time => column_data - .as_any() - .downcast_ref::() - .map(int64_from_nanoseconds), - - TimeType::Sequence => column_data - .as_any() - .downcast_ref::() - .cloned(), - }; + let time_data_result = column_data + .as_any() + .downcast_ref::() + .cloned() + .or_else(|| { + column_data + .as_any() + .downcast_ref::() + .and_then(int64_from_nanoseconds) + }); let time_data = time_data_result.ok_or_else(|| { DisplayRecordBatchError::UnexpectedTimeColumnDataType( timeline.name().as_str().to_owned(),