Skip to content

Commit

Permalink
Use arrow1 for formatting of arrow data in UI (#8592)
Browse files Browse the repository at this point in the history
### Related
* Follow-up to #8590
* Part of #3741
* ~Blocked on apache/arrow-rs#6951

### What
Uses `arrow-rs` own formatting of arrow values.

Unfortunately this adds a `.0` suffix to all integer floating point
values, which makes them quite verbose. I will see if there is a way
around that.
  • Loading branch information
emilk authored Jan 7, 2025
1 parent c9e8183 commit a2400fd
Show file tree
Hide file tree
Showing 35 changed files with 95 additions and 108 deletions.
1 change: 0 additions & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6551,7 +6551,6 @@ dependencies = [
"parking_lot",
"rand",
"re_arrow2",
"re_byte_size",
"re_entity_db",
"re_format",
"re_log",
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion crates/viewer/re_ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ arrow = ["dep:arrow", "dep:arrow2"]

[dependencies]
re_entity_db.workspace = true # syntax-highlighting for InstancePath. TODO(emilk): move InstancePath
re_byte_size.workspace = true
re_format.workspace = true
re_log.workspace = true
re_log_types.workspace = true # syntax-highlighting for EntityPath
Expand Down
73 changes: 31 additions & 42 deletions crates/viewer/re_ui/src/arrow_ui.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
use arrow2::array::Utf8Array;
use arrow::util::display::{ArrayFormatter, FormatOptions};
use itertools::Itertools as _;

use re_byte_size::SizeBytes as _;

use crate::{UiExt as _, UiLayout};
use crate::UiLayout;

pub 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(),
);
}
use arrow::array::{LargeStringArray, StringArray};

pub fn arrow2_ui(ui: &mut egui::Ui, ui_layout: UiLayout, array: &dyn arrow2::array::Array) {
ui.scope(|ui| {
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Truncate);

Expand All @@ -24,51 +16,44 @@ pub fn arrow2_ui(ui: &mut egui::Ui, ui_layout: UiLayout, array: &dyn arrow2::arr

// Special-treat text.
// Note: we match on the raw data here, so this works for any component containing text.
if let Some(utf8) = array.as_any().downcast_ref::<Utf8Array<i32>>() {
if utf8.len() == 1 {
if let Some(utf8) = array.as_any().downcast_ref::<StringArray>() {
if utf8.values().len() == 1 {
let string = utf8.value(0);
ui_layout.data_label(ui, string);
return;
}
}
if let Some(utf8) = array.as_any().downcast_ref::<Utf8Array<i64>>() {
if utf8.len() == 1 {
if let Some(utf8) = array.as_any().downcast_ref::<LargeStringArray>() {
if utf8.values().len() == 1 {
let string = utf8.value(0);
ui_layout.data_label(ui, string);
return;
}
}

let num_bytes = array.total_size_bytes();
if num_bytes < 3000 {
let num_bytes = array.get_array_memory_size();
if num_bytes < 3_000 {
let instance_count = array.len();
let display = arrow2::array::get_display(array, "null");

if instance_count == 1 {
let mut string = String::new();
match display(&mut string, 0) {
Ok(_) => ui.monospace(&string),
Err(err) => ui.error_with_details_on_hover(err.to_string()),
};
return;
} else {
ui_layout
.label(ui, format!("{instance_count} items"))
.on_hover_ui(|ui| {
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Wrap);
ui.monospace(format!(
"[{}]",
(0..instance_count)
.filter_map(|index| {
let mut s = String::new();
//TODO(ab): should we care about errors here?
display(&mut s, index).ok().map(|_| s)
})
.join(", ")
));
});
let options = FormatOptions::default();
if let Ok(formatter) = ArrayFormatter::try_new(array, &options) {
if instance_count == 1 {
ui.monospace(formatter.value(0).to_string());
return;
} else {
ui_layout
.label(ui, format!("{instance_count} items"))
.on_hover_ui(|ui| {
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Wrap);
ui.monospace(format!(
"[{}]",
(0..instance_count)
.map(|index| formatter.value(index).to_string())
.join(", ")
));
});
}
}

return;
}

Expand All @@ -87,3 +72,7 @@ pub fn arrow2_ui(ui: &mut egui::Ui, ui_layout: UiLayout, array: &dyn arrow2::arr
}
});
}

pub fn arrow2_ui(ui: &mut egui::Ui, ui_layout: UiLayout, array: &dyn arrow2::array::Array) {
arrow_ui(ui, ui_layout, &arrow::array::ArrayRef::from(array));
}
4 changes: 2 additions & 2 deletions crates/viewer/re_ui/tests/snapshots/arrow_ui.png

0 comments on commit a2400fd

Please sign in to comment.