Skip to content

Commit

Permalink
Don't crash
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jan 6, 2025
1 parent 98f1d29 commit bc4f4ab
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions crates/viewer/re_view_dataframe/src/display_record_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,32 +183,31 @@ impl DisplayColumn {
) -> Result<Self, DisplayRecordBatchError> {
fn int64_from_nanoseconds(
duration_array: &ArrowTimestampNanosecondArray,
) -> ArrowInt64Array {
) -> Option<ArrowInt64Array> {
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::<ArrowTimestampNanosecondArray>()
.map(int64_from_nanoseconds),

TimeType::Sequence => column_data
.as_any()
.downcast_ref::<ArrowInt64Array>()
.cloned(),
};
let time_data_result = column_data
.as_any()
.downcast_ref::<ArrowInt64Array>()
.cloned()
.or_else(|| {
column_data
.as_any()
.downcast_ref::<ArrowTimestampNanosecondArray>()
.and_then(int64_from_nanoseconds)
});
let time_data = time_data_result.ok_or_else(|| {
DisplayRecordBatchError::UnexpectedTimeColumnDataType(
timeline.name().as_str().to_owned(),
Expand Down

0 comments on commit bc4f4ab

Please sign in to comment.