Skip to content

Commit

Permalink
Client-side chunks 0: improved arrow chunk formatters (#6437)
Browse files Browse the repository at this point in the history
This new and improved `re_format_arrow` ™️ brings two major
improvements:
- It is now designed to format standard Arrow dataframes (aka chunks or
batches), i.e. a `Schema` and a `Chunk`.
In particular: chunk-level and field-level schema metadata will now be
rendered properly with the rest of the table.
- Tables larger than your terminal will now do their best to fit in,
while making sure to still show just enough data.

E.g. here's an excerpt of a real-world Rerun dataframe from our `helix`
example:
```
cargo r -p rerun-cli --no-default-features --features native_viewer -- print helix.rrd --verbose
```

before (`main`):

![image](https://github.com/rerun-io/rerun/assets/2910679/99169b2a-d972-439d-900a-8f122a4d5ca3)

and after:

![image](https://github.com/rerun-io/rerun/assets/2910679/3fe7acce-d646-4ff2-bfae-eb5073d17741)


---

Part of a PR series to implement our new chunk-based data model on the
client-side (SDKs):
- #6437
- #6438
- #6439
- #6440
- #6441
  • Loading branch information
teh-cmc authored May 31, 2024
1 parent 1211f6d commit 7ecdfcc
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 118 deletions.
76 changes: 43 additions & 33 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1145,10 +1145,11 @@ dependencies = [

[[package]]
name = "comfy-table"
version = "7.1.0"
version = "7.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7c64043d6c7b7a4c58e39e7efccfdea7b93d885a795d0c054a69dbbf4dd52686"
checksum = "b34115915337defe99b2aff5c2ce6771e5fbc4079f4b506301f5cf394c8452f7"
dependencies = [
"crossterm",
"strum",
"strum_macros",
"unicode-width",
Expand Down Expand Up @@ -1356,6 +1357,28 @@ dependencies = [
"cfg-if",
]

[[package]]
name = "crossterm"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f476fe445d41c9e991fd07515a6f463074b782242ccf4a5b7b1d1012e70824df"
dependencies = [
"bitflags 2.4.1",
"crossterm_winapi",
"libc",
"parking_lot",
"winapi",
]

[[package]]
name = "crossterm_winapi"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b"
dependencies = [
"winapi",
]

[[package]]
name = "crunchy"
version = "0.2.2"
Expand Down Expand Up @@ -2605,9 +2628,9 @@ dependencies = [

[[package]]
name = "indoc"
version = "2.0.4"
version = "2.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e186cfbae8084e513daff4240b4797e342f988cecda4fb6c939150f96315fd8"
checksum = "b248f5224d1d606005e02c97f5aa4e88eeb230488bcc03bc9ca4d7991399f2b5"

[[package]]
name = "infer"
Expand Down Expand Up @@ -3107,9 +3130,9 @@ dependencies = [

[[package]]
name = "multimap"
version = "0.8.3"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a"
checksum = "defc4c55412d89136f966bbb339008b474350e5e6e78d2714439c386b3137a03"

[[package]]
name = "naga"
Expand Down Expand Up @@ -3884,23 +3907,23 @@ dependencies = [

[[package]]
name = "prost"
version = "0.12.3"
version = "0.12.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "146c289cda302b98a28d40c8b3b90498d6e526dd24ac2ecea73e4e491685b94a"
checksum = "deb1435c188b76130da55f17a466d252ff7b1418b2ad3e037d127b94e3411f29"
dependencies = [
"bytes",
"prost-derive",
]

[[package]]
name = "prost-build"
version = "0.12.3"
version = "0.12.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c55e02e35260070b6f716a2423c2ff1c3bb1642ddca6f99e1f26d06268a0e2d2"
checksum = "22505a5c94da8e3b7c2996394d1c933236c4d743e81a410bcca4e6989fc066a4"
dependencies = [
"bytes",
"heck 0.4.1",
"itertools 0.10.5",
"itertools 0.12.0",
"log",
"multimap",
"once_cell",
Expand All @@ -3911,27 +3934,26 @@ dependencies = [
"regex",
"syn 2.0.48",
"tempfile",
"which",
]

[[package]]
name = "prost-derive"
version = "0.12.3"
version = "0.12.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efb6c9a1dd1def8e2124d17e83a20af56f1570d6c2d2bd9e266ccb768df3840e"
checksum = "81bddcdb20abf9501610992b6759a4c888aef7d1a7247ef75e2404275ac24af1"
dependencies = [
"anyhow",
"itertools 0.10.5",
"itertools 0.12.0",
"proc-macro2",
"quote",
"syn 2.0.48",
]

[[package]]
name = "prost-types"
version = "0.12.3"
version = "0.12.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "193898f59edcf43c26227dcd4c8427f00d99d61e95dcde58dabd49fa291d470e"
checksum = "9091c90b0a32608e984ff2fa4091273cbdd755d54935c51d520887f4a1dbd5b0"
dependencies = [
"prost",
]
Expand Down Expand Up @@ -6259,18 +6281,18 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"

[[package]]
name = "strum"
version = "0.25.0"
version = "0.26.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125"
checksum = "5d8cec3501a5194c432b2b7976db6b7d10ec95c253208b45f83f7136aa985e29"
dependencies = [
"strum_macros",
]

[[package]]
name = "strum_macros"
version = "0.25.3"
version = "0.26.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0"
checksum = "c6cf59daf282c0a494ba14fd21610a0325f9f90ec9d1231dea26bcb1d696c946"
dependencies = [
"heck 0.4.1",
"proc-macro2",
Expand Down Expand Up @@ -7288,18 +7310,6 @@ dependencies = [
"web-sys",
]

[[package]]
name = "which"
version = "4.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7"
dependencies = [
"either",
"home",
"once_cell",
"rustix 0.38.24",
]

[[package]]
name = "widestring"
version = "1.0.2"
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ similar-asserts = "1.4.2"
slotmap = { version = "1.0.6", features = ["serde"] }
smallvec = { version = "1.0", features = ["const_generics", "union"] }
static_assertions = "1.1"
strum = { version = "0.25", features = ["derive"] }
strum_macros = "0.25"
strum = { version = "0.26", features = ["derive"] }
strum_macros = "0.26"
sublime_fuzzy = "0.7"
syn = "2.0"
sysinfo = { version = "0.30.1", default-features = false }
Expand Down
15 changes: 9 additions & 6 deletions crates/re_data_store/src/store_format.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use arrow2::datatypes::Metadata;
use re_format::{format_bytes, format_uint};
use re_log_types::TimeInt;
use re_types_core::SizeBytes as _;
Expand Down Expand Up @@ -138,9 +139,10 @@ impl std::fmt::Display for IndexedBucket {
re_log::error_once!("couldn't display indexed bucket: {err}");
std::fmt::Error
})?;
re_format_arrow::format_table(
columns.columns(),
schema.fields.iter().map(|field| field.name.as_str()),
re_format_arrow::format_dataframe(
Metadata::default(),
&schema.fields,
columns.columns().iter().map(|array| &**array),
)
.fmt(f)?;

Expand Down Expand Up @@ -170,9 +172,10 @@ impl std::fmt::Display for StaticTable {
re_log::error_once!("couldn't display static table: {err}");
std::fmt::Error
})?;
re_format_arrow::format_table(
columns.columns(),
schema.fields.iter().map(|field| field.name.as_str()),
re_format_arrow::format_dataframe(
Metadata::default(),
&schema.fields,
columns.columns().iter().map(|array| &**array),
)
.fmt(f)?;

Expand Down
9 changes: 8 additions & 1 deletion crates/re_format_arrow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ all-features = true

[dependencies]
arrow2.workspace = true
comfy-table.workspace = true
re_tuid.workspace = true
re_types_core.workspace = true # tuid serialization

# native dependencies:
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
comfy-table = { workspace = true, features = ["tty"] }

# web dependencies:
[target.'cfg(target_arch = "wasm32")'.dependencies]
comfy-table = { workspace = true }
Loading

0 comments on commit 7ecdfcc

Please sign in to comment.