Skip to content

Commit

Permalink
Less arrow2
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Dec 18, 2024
1 parent ea04ea5 commit 512a671
Show file tree
Hide file tree
Showing 23 changed files with 119 additions and 96 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5701,6 +5701,7 @@ dependencies = [
name = "re_component_ui"
version = "0.21.0-alpha.1+dev"
dependencies = [
"arrow",
"egui",
"egui_extras",
"egui_plot",
Expand Down Expand Up @@ -6297,6 +6298,7 @@ dependencies = [
name = "re_selection_panel"
version = "0.21.0-alpha.1+dev"
dependencies = [
"arrow",
"egui",
"egui_tiles",
"itertools 0.13.0",
Expand Down Expand Up @@ -6597,6 +6599,7 @@ name = "re_view_dataframe"
version = "0.21.0-alpha.1+dev"
dependencies = [
"anyhow",
"arrow",
"egui",
"egui_table",
"itertools 0.13.0",
Expand Down
18 changes: 18 additions & 0 deletions crates/store/re_chunk/src/builder.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use arrow::array::ArrayRef;
use arrow2::{
array::{Array as Arrow2Array, PrimitiveArray as Arrow2PrimitiveArray},
datatypes::DataType as Arrow2Datatype,
Expand Down Expand Up @@ -99,6 +100,23 @@ impl ChunkBuilder {
self
}

/// Add a row's worth of data using the given component data.
#[inline]
pub fn with_row_arrow1(
self,
row_id: RowId,
timepoint: impl Into<TimePoint>,
components: impl IntoIterator<Item = (ComponentDescriptor, ArrayRef)>,
) -> Self {
self.with_sparse_row(
row_id,
timepoint,
components
.into_iter()
.map(|(component_descr, array)| (component_descr, Some(array.into()))),
)
}

/// Add a row's worth of data using the given component data.
#[inline]
pub fn with_row(
Expand Down
13 changes: 11 additions & 2 deletions crates/store/re_query/src/latest_at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use re_chunk::{Chunk, RowId, UnitChunkShared};
use re_chunk_store::{ChunkStore, LatestAtQuery, TimeInt};
use re_log_types::EntityPath;
use re_types_core::{
components::ClearIsRecursive, Component, ComponentDescriptor, ComponentName, SizeBytes,
components::ClearIsRecursive, external::arrow::array::ArrayRef, Component, ComponentDescriptor,
ComponentName, SizeBytes,
};

use crate::{QueryCache, QueryCacheKey, QueryError};
Expand Down Expand Up @@ -313,7 +314,15 @@ impl LatestAtResults {

/// Returns the raw data for the specified component.
#[inline]
pub fn component_batch_raw(
pub fn component_batch_raw(&self, component_name: &ComponentName) -> Option<ArrayRef> {
self.components
.get(component_name)?
.component_batch_raw(component_name)
}

/// Returns the raw data for the specified component.
#[inline]
pub fn component_batch_raw_arrow2(
&self,
component_name: &ComponentName,
) -> Option<Box<dyn Arrow2Array>> {
Expand Down
1 change: 1 addition & 0 deletions crates/viewer/re_component_ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ re_types_core.workspace = true
re_ui.workspace = true
re_viewer_context.workspace = true

arrow.workspace = true
egui_extras.workspace = true
egui_plot.workspace = true
egui.workspace = true
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use re_types::{
components::{Name, Text},
datatypes::Utf8,
external::arrow2,
Loggable as _,
};
use re_ui::UiExt as _;
Expand Down Expand Up @@ -84,9 +83,9 @@ pub fn display_text_ui(
_db: &EntityDb,
_path: &EntityPath,
_row_id: Option<RowId>,
data: &dyn arrow2::array::Array,
data: &dyn arrow::array::Array,
) {
let text = match Text::from_arrow2(data) {
let text = match Text::from_arrow(data) {
Ok(text) => text.first().cloned(),
Err(err) => {
ui.error_label("Failed to deserialize")
Expand All @@ -113,9 +112,9 @@ pub fn display_name_ui(
_db: &EntityDb,
_path: &EntityPath,
_row_id: Option<RowId>,
data: &dyn arrow2::array::Array,
data: &dyn arrow::array::Array,
) {
let name = match Name::from_arrow2(data) {
let name = match Name::from_arrow(data) {
Ok(name) => name.first().cloned(),
Err(err) => {
ui.error_label("Failed to deserialize")
Expand Down
12 changes: 10 additions & 2 deletions crates/viewer/re_component_ui/src/fallback_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,20 @@ pub fn fallback_component_ui(
_db: &EntityDb,
_entity_path: &EntityPath,
_row_id: Option<RowId>,
component: &dyn arrow2::array::Array,
component: &dyn arrow::array::Array,
) {
arrow_ui(ui, ui_layout, component);
}

fn arrow_ui(ui: &mut egui::Ui, ui_layout: UiLayout, array: &dyn arrow2::array::Array) {
fn arrow_ui(ui: &mut egui::Ui, ui_layout: UiLayout, array: &dyn arrow::array::Array) {
arrow2_ui(
ui,
ui_layout,
Box::<dyn arrow2::array::Array>::from(array).as_ref(),
);
}

fn arrow2_ui(ui: &mut egui::Ui, ui_layout: UiLayout, array: &dyn arrow2::array::Array) {
use re_types::SizeBytes as _;

// Special-treat text.
Expand Down
2 changes: 1 addition & 1 deletion crates/viewer/re_data_ui/src/component_ui_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn add_to_registry<C: EntityDataUi + re_types::Component>(registry: &mut Com
registry.add_legacy_display_ui(
C::name(),
Box::new(
|ctx, ui, ui_layout, query, db, entity_path, row_id, component_raw| match C::from_arrow2(
|ctx, ui, ui_layout, query, db, entity_path, row_id, component_raw| match C::from_arrow(
component_raw,
) {
Ok(components) => match components.len() {
Expand Down
1 change: 1 addition & 0 deletions crates/viewer/re_selection_panel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ re_ui.workspace = true
re_viewer_context.workspace = true
re_viewport_blueprint.workspace = true

arrow.workspace = true
egui_tiles.workspace = true
egui.workspace = true
itertools.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/viewer/re_selection_panel/src/defaults_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ fn active_defaults(
db.storage_engine()
.cache()
.latest_at(query, &view.defaults_path, [*c])
.component_batch_raw(c)
.component_batch_raw_arrow2(c)
.map_or(false, |data| !data.is_empty())
})
.collect::<BTreeSet<_>>()
Expand Down
31 changes: 15 additions & 16 deletions crates/viewer/re_selection_panel/src/visualizer_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use re_data_ui::{sorted_component_list_for_ui, DataUi};
use re_entity_db::EntityDb;
use re_log_types::{ComponentPath, EntityPath};
use re_types::blueprint::components::VisualizerOverrides;
use re_types::external::arrow2;
use re_types_core::external::arrow::array::ArrayRef;
use re_ui::{list_item, UiExt as _};
use re_view::latest_at_with_blueprint_resolved_data;
use re_viewer_context::{
Expand Down Expand Up @@ -160,9 +160,9 @@ fn visualizer_components(
fn non_empty_component_batch_raw(
unit: Option<&UnitChunkShared>,
component_name: &ComponentName,
) -> Option<(Option<RowId>, Box<dyn re_chunk::Arrow2Array>)> {
) -> Option<(Option<RowId>, ArrayRef)> {
let unit = unit?;
let batch = unit.component_batch_raw_arrow2(component_name)?;
let batch = unit.component_batch_raw(component_name)?;
if batch.is_empty() {
None
} else {
Expand Down Expand Up @@ -205,10 +205,9 @@ fn visualizer_components(
let result_default = query_result.defaults.get(&component_name);
let raw_default = non_empty_component_batch_raw(result_default, &component_name);

let raw_fallback: Box<dyn re_chunk::Arrow2Array> = visualizer
let raw_fallback = visualizer
.fallback_provider()
.fallback_for(&query_ctx, component_name)
.into();
.fallback_for(&query_ctx, component_name);

// Determine where the final value comes from.
// Putting this into an enum makes it easier to reason about the next steps.
Expand Down Expand Up @@ -398,8 +397,8 @@ fn visualizer_components(
override_path,
&raw_override.clone().map(|(_, raw_override)| raw_override),
raw_default.clone().map(|(_, raw_override)| raw_override),
raw_fallback.as_ref(),
raw_current_value.as_ref(),
raw_fallback.clone(),
raw_current_value.clone(),
);
}),
add_children,
Expand All @@ -418,7 +417,7 @@ fn editable_blueprint_component_list_item(
blueprint_path: &EntityPath,
component: re_types::ComponentName,
row_id: Option<RowId>,
raw_override: &dyn arrow2::array::Array,
raw_override: &dyn arrow::array::Array,
) -> egui::Response {
ui.list_item_flat_noninteractive(
list_item::PropertyContent::new(name)
Expand Down Expand Up @@ -450,10 +449,10 @@ fn menu_more(
ui: &mut egui::Ui,
component_name: re_types::ComponentName,
override_path: &EntityPath,
raw_override: &Option<Box<dyn arrow2::array::Array>>,
raw_default: Option<Box<dyn arrow2::array::Array>>,
raw_fallback: &dyn arrow2::array::Array,
raw_current_value: &dyn arrow2::array::Array,
raw_override: &Option<ArrayRef>,
raw_default: Option<ArrayRef>,
raw_fallback: arrow::array::ArrayRef,
raw_current_value: arrow::array::ArrayRef,
) {
if ui
.add_enabled(raw_override.is_some(), egui::Button::new("Remove override"))
Expand All @@ -479,14 +478,14 @@ fn menu_more(
}

if ui.button("Set to fallback value").clicked() {
ctx.save_blueprint_array(override_path, component_name, raw_fallback.to_boxed());
ctx.save_blueprint_array(override_path, component_name, raw_fallback);
ui.close_menu();
}

let override_differs_from_default = raw_override
!= &ctx
.viewer_ctx
.raw_latest_at_in_default_blueprint_arrow2(override_path, component_name);
.raw_latest_at_in_default_blueprint(override_path, component_name);
if ui
.add_enabled(
override_differs_from_default,
Expand All @@ -504,7 +503,7 @@ fn menu_more(
ctx.save_blueprint_array(
&ViewBlueprint::defaults_path(ctx.view_id),
component_name,
raw_current_value.to_boxed(),
raw_current_value,
);
ui.close_menu();
}
Expand Down
4 changes: 1 addition & 3 deletions crates/viewer/re_view/src/view_property_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ pub fn view_property_component_ui(
field: &ArchetypeFieldReflection,
fallback_provider: &dyn ComponentFallbackProvider,
) {
let component_array: Option<Box<dyn arrow2::array::Array>> = property
.component_raw(field.component_name)
.map(|array| array.into());
let component_array = property.component_raw(field.component_name);
let row_id = property.component_row_id(field.component_name);

let ui_types = ctx
Expand Down
1 change: 1 addition & 0 deletions crates/viewer/re_view_dataframe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ re_viewer_context.workspace = true
re_viewport_blueprint.workspace = true

anyhow.workspace = true
arrow.workspace = true
egui_table.workspace = true
egui.workspace = true
itertools.workspace = true
Expand Down
4 changes: 3 additions & 1 deletion crates/viewer/re_view_dataframe/src/display_record_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ impl ComponentData {
data
};

let data_to_display: arrow::array::ArrayRef = data_to_display.into();

ctx.component_ui_registry.ui_raw(
ctx,
ui,
Expand All @@ -154,7 +156,7 @@ impl ComponentData {
entity_path,
component_name,
None,
&*data_to_display,
data_to_display.as_ref(),
);
} else {
ui.label("-");
Expand Down
5 changes: 1 addition & 4 deletions crates/viewer/re_view_graph/src/ui/selection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use re_chunk::Arrow2Array;
use re_types::{
blueprint::components::Enabled, Archetype, ArchetypeReflectionMarker, Component as _,
};
Expand Down Expand Up @@ -62,9 +61,7 @@ pub fn view_property_force_ui<A: Archetype + ArchetypeReflectionMarker>(
.find(|field| field.component_name == Enabled::name())
.expect("forces are required to have an `Enabled` component");

let component_array: Option<Box<dyn Arrow2Array>> = property
.component_raw(field.component_name)
.map(|array| array.into());
let component_array = property.component_raw(field.component_name);
let row_id = property.component_row_id(field.component_name);

let singleline_ui: &dyn Fn(&mut egui::Ui) = &|ui| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ pub fn show_labels_fallback<C: Component>(ctx: &re_viewer_context::QueryContext<
ctx.recording()
.latest_at(ctx.query, ctx.target_entity_path, [C::name(), Text::name()]);
let num_instances = results
.component_batch_raw(&C::name())
.component_batch_raw_arrow2(&C::name())
.map_or(0, |array| array.len());
let num_labels = results
.component_batch_raw(&Text::name())
.component_batch_raw_arrow2(&Text::name())
.map_or(0, |array| array.len());

ShowLabels::from(num_labels == 1 || num_instances < MAX_NUM_LABELS_PER_ENTITY)
Expand Down
2 changes: 1 addition & 1 deletion crates/viewer/re_viewer/src/blueprint/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub(crate) fn validate_component<C: Component>(blueprint: &EntityDb) -> bool {
if let Some(array) = engine
.cache()
.latest_at(&query, path, [C::name()])
.component_batch_raw(&C::name())
.component_batch_raw_arrow2(&C::name())
{
if let Err(err) = C::from_arrow2_opt(&*array) {
re_log::debug!(
Expand Down
18 changes: 4 additions & 14 deletions crates/viewer/re_viewer_context/src/blueprint_helpers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use arrow::array::ArrayRef;
use re_chunk::{Arrow2Array, RowId};
use re_chunk::RowId;
use re_chunk_store::external::re_chunk::Chunk;
use re_log_types::{EntityPath, TimeInt, TimePoint, Timeline};
use re_types::{AsComponents, ComponentBatch, ComponentDescriptor, ComponentName};
Expand Down Expand Up @@ -87,12 +87,12 @@ impl ViewerContext<'_> {
&self,
entity_path: &EntityPath,
component_name: ComponentName,
array: Box<dyn Arrow2Array>,
array: ArrayRef,
) {
let timepoint = self.store_context.blueprint_timepoint_for_writes();

let chunk = match Chunk::builder(entity_path.clone())
.with_row(
.with_row_arrow1(
RowId::new(),
timepoint.clone(),
[(ComponentDescriptor::new(component_name), array)],
Expand Down Expand Up @@ -138,24 +138,14 @@ impl ViewerContext<'_> {
})
}

/// Queries a raw component from the default blueprint.
pub fn raw_latest_at_in_default_blueprint_arrow2(
&self,
entity_path: &EntityPath,
component_name: ComponentName,
) -> Option<Box<dyn Arrow2Array>> {
self.raw_latest_at_in_default_blueprint(entity_path, component_name)
.map(|array| array.into())
}

/// Resets a blueprint component to the value it had in the default blueprint.
pub fn reset_blueprint_component_by_name(
&self,
entity_path: &EntityPath,
component_name: ComponentName,
) {
if let Some(default_value) =
self.raw_latest_at_in_default_blueprint_arrow2(entity_path, component_name)
self.raw_latest_at_in_default_blueprint(entity_path, component_name)
{
self.save_blueprint_array(entity_path, component_name, default_value);
} else {
Expand Down
Loading

0 comments on commit 512a671

Please sign in to comment.