From 10cbe6187f77b62d8160397f4d8c9a550dedcec5 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 6 Jan 2025 22:09:14 +0100 Subject: [PATCH] Use arrow1 datatype in reflection --- .../src/codegen/rust/reflection.rs | 2 +- crates/store/re_types/src/reflection/mod.rs | 218 +++++++++--------- crates/store/re_types_core/src/reflection.rs | 18 +- .../re_viewer_context/src/viewer_context.rs | 9 +- 4 files changed, 126 insertions(+), 121 deletions(-) diff --git a/crates/build/re_types_builder/src/codegen/rust/reflection.rs b/crates/build/re_types_builder/src/codegen/rust/reflection.rs index 191dde948f92..8c86c4e37641 100644 --- a/crates/build/re_types_builder/src/codegen/rust/reflection.rs +++ b/crates/build/re_types_builder/src/codegen/rust/reflection.rs @@ -146,7 +146,7 @@ fn generate_component_reflection( ComponentReflection { docstring_md: #docstring_md, custom_placeholder: #custom_placeholder, - datatype: #type_name::arrow2_datatype(), + datatype: #type_name::arrow_datatype(), } }; quoted_pairs.push(quote! { (#quoted_name, #quoted_reflection) }); diff --git a/crates/store/re_types/src/reflection/mod.rs b/crates/store/re_types/src/reflection/mod.rs index 31cc885c6114..bbc5cc219b2b 100644 --- a/crates/store/re_types/src/reflection/mod.rs +++ b/crates/store/re_types/src/reflection/mod.rs @@ -38,7 +38,7 @@ fn generate_component_reflection() -> Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result\n\nThis can only be used as part of blueprints. It will have no effect if used\nin a regular entity.", custom_placeholder: Some(VisualizerOverrides::default().to_arrow()?), - datatype: VisualizerOverrides::arrow2_datatype(), + datatype: VisualizerOverrides::arrow_datatype(), }, ), ( @@ -346,7 +346,7 @@ fn generate_component_reflection() -> Result Result Result Result Result Result Result Result Result Result Resultdepth map scaling factor.\n\nThis measures how many depth map units are in a world unit.\nFor instance, if a depth map uses millimeters and the world uses meters,\nthis value would be `1000`.\n\nNote that the only effect on 2D views is the physical depth values shown when hovering the image.\nIn 3D views on the other hand, this affects where the points of the point cloud are placed.", custom_placeholder: Some(DepthMeter::default().to_arrow()?), - datatype: DepthMeter::arrow2_datatype(), + datatype: DepthMeter::arrow_datatype(), }, ), ( @@ -434,7 +434,7 @@ fn generate_component_reflection() -> Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result.", custom_placeholder: Some(MediaType::default().to_arrow()?), - datatype: MediaType::arrow2_datatype(), + datatype: MediaType::arrow_datatype(), }, ), ( @@ -618,7 +618,7 @@ fn generate_component_reflection() -> Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result Result arrow::array::ArrayRef { + generic_placeholder_for_datatype_arrow2(&datatype.clone().into()).into() +} + +fn generic_placeholder_for_datatype_arrow2( datatype: &arrow2::datatypes::DataType, ) -> Box { use arrow2::{ @@ -121,7 +127,7 @@ pub fn generic_placeholder_for_datatype( DataType::Utf8 => Box::new(array::Utf8Array::::from_slice([""])), DataType::LargeUtf8 => Box::new(array::Utf8Array::::from_slice([""])), DataType::List(field) => { - let inner = generic_placeholder_for_datatype(field.data_type()); + let inner = generic_placeholder_for_datatype_arrow2(field.data_type()); let offsets = arrow2::offset::Offsets::try_from_lengths(std::iter::once(inner.len())) .expect("failed to create offsets buffer"); Box::new(array::ListArray::::new( @@ -140,7 +146,7 @@ pub fn generic_placeholder_for_datatype( } DataType::LargeList(field) => { - let inner = generic_placeholder_for_datatype(field.data_type()); + let inner = generic_placeholder_for_datatype_arrow2(field.data_type()); let offsets = arrow2::offset::Offsets::try_from_lengths(std::iter::once(inner.len())) .expect("failed to create offsets buffer"); Box::new(array::ListArray::::new( @@ -153,7 +159,7 @@ pub fn generic_placeholder_for_datatype( DataType::Struct(fields) => { let inners = fields .iter() - .map(|field| generic_placeholder_for_datatype(field.data_type())); + .map(|field| generic_placeholder_for_datatype_arrow2(field.data_type())); Box::new(array::StructArray::new( datatype.clone(), inners.collect(), @@ -162,7 +168,7 @@ pub fn generic_placeholder_for_datatype( } DataType::Union(fields, _types, _union_mode) => { if let Some(first_field) = fields.first() { - let first_field = generic_placeholder_for_datatype(first_field.data_type()); + let first_field = generic_placeholder_for_datatype_arrow2(first_field.data_type()); let first_field_len = first_field.len(); // Should be 1, but let's play this safe! let other_fields = fields .iter() @@ -199,7 +205,7 @@ pub fn generic_placeholder_for_datatype( )])) } - DataType::Extension(_, datatype, _) => generic_placeholder_for_datatype(datatype), + DataType::Extension(_, datatype, _) => generic_placeholder_for_datatype_arrow2(datatype), } } @@ -223,7 +229,7 @@ pub struct ComponentReflection { pub custom_placeholder: Option, /// Datatype of the component. - pub datatype: arrow2::datatypes::DataType, + pub datatype: arrow::datatypes::DataType, } /// Runtime reflection about archetypes. diff --git a/crates/viewer/re_viewer_context/src/viewer_context.rs b/crates/viewer/re_viewer_context/src/viewer_context.rs index 10e2c7625027..52ea2b6988a6 100644 --- a/crates/viewer/re_viewer_context/src/viewer_context.rs +++ b/crates/viewer/re_viewer_context/src/viewer_context.rs @@ -238,18 +238,17 @@ impl ViewerContext<'_> { } else { self.recording_engine() .store() - .lookup_datatype_arrow2(&component) - .cloned() - .or_else(|| self.blueprint_engine().store().lookup_datatype_arrow2(&component).cloned()) + .lookup_datatype(&component) + .or_else(|| self.blueprint_engine().store().lookup_datatype(&component)) .unwrap_or_else(|| { re_log::error_once!("Could not find datatype for component {component}. Using null array as placeholder."); - re_chunk::external::arrow2::datatypes::DataType::Null + arrow::datatypes::DataType::Null }) }; // TODO(andreas): Is this operation common enough to cache the result? If so, here or in the reflection data? // The nice thing about this would be that we could always give out references (but updating said cache wouldn't be easy in that case). - re_types::reflection::generic_placeholder_for_datatype(&datatype).into() + re_types::reflection::generic_placeholder_for_datatype(&datatype) } }