From 13aaf3e68cea6a069619b13c3dd76de7ee534840 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 28 Aug 2024 18:54:38 +0200 Subject: [PATCH] Revert "Remove unused `Loggable::extended_arrow_datatype` (#7260)" This reverts commit 0252f6badfb7b4b83522650822e88014522432cc. --- crates/store/re_types_core/src/loggable.rs | 17 +++++++++++++++++ crates/store/re_types_core/src/tuid.rs | 8 +------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/crates/store/re_types_core/src/loggable.rs b/crates/store/re_types_core/src/loggable.rs index dd09ff2f60bc..b574ce7f92c2 100644 --- a/crates/store/re_types_core/src/loggable.rs +++ b/crates/store/re_types_core/src/loggable.rs @@ -1,3 +1,5 @@ +use std::sync::Arc; + use crate::{ result::_Backtrace, DeserializationResult, ResultExt as _, SerializationResult, SizeBytes, }; @@ -39,6 +41,21 @@ pub trait Loggable: 'static + Send + Sync + Clone + Sized + SizeBytes { where Self: 'a; + // --- Optional metadata methods --- + + /// The underlying [`arrow2::datatypes::DataType`], including datatype extensions. + /// + /// The default implementation will simply wrap [`Self::arrow_datatype`] in an extension called + /// [`Self::name`], which is what you want in most cases. + #[inline] + fn extended_arrow_datatype() -> arrow2::datatypes::DataType { + arrow2::datatypes::DataType::Extension( + Self::name().to_string(), + Arc::new(Self::arrow_datatype()), + None, + ) + } + // --- Optional serialization methods --- /// Given an iterator of owned or reference values to the current [`Loggable`], serializes diff --git a/crates/store/re_types_core/src/tuid.rs b/crates/store/re_types_core/src/tuid.rs index 153f73110817..917393853d1a 100644 --- a/crates/store/re_types_core/src/tuid.rs +++ b/crates/store/re_types_core/src/tuid.rs @@ -64,14 +64,8 @@ impl Loggable for Tuid { ]; let validity = None; - let datatype = arrow2::datatypes::DataType::Extension( - Self::name().to_string(), - Arc::new(Self::arrow_datatype()), - None, - ); - // TODO(cmc): We use the extended type here because we rely on it for formatting. - Ok(StructArray::new(datatype, values, validity).boxed()) + Ok(StructArray::new(Self::extended_arrow_datatype(), values, validity).boxed()) } fn from_arrow(array: &dyn ::arrow2::array::Array) -> crate::DeserializationResult> {