Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codegen'd Rust/Arrow (de)ser 9: Rust backport! #2571

Merged
merged 8 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/re_sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ re_log_types.workspace = true
re_log.workspace = true
re_memory.workspace = true
re_sdk_comms = { workspace = true, features = ["client"] }
re_types = { workspace = true, features = ["ecolor", "glam"] }

ahash.workspace = true
crossbeam.workspace = true
Expand Down
5 changes: 5 additions & 0 deletions crates/re_sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ pub mod coordinates {
pub use re_components::coordinates::{Axis3, Handedness, Sign, SignedAxis3};
}

/// Experimental APIs, to try out upcoming Rerun features.
pub mod experimental {
pub use re_types::{archetypes, components, datatypes, Archetype, Component, Datatype};
}

/// Re-exports of other crates.
pub mod external {
pub use re_log;
Expand Down
31 changes: 30 additions & 1 deletion crates/re_sdk/src/msg_sender.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use re_log_types::{DataRow, DataTableError, InstanceKey, RowId, StoreId};
use re_log_types::{
external::arrow2::datatypes::DataType, DataRow, DataTableError, InstanceKey, RowId, StoreId,
};
use re_types::Archetype;

use crate::{
log::DataCell,
Expand Down Expand Up @@ -102,6 +105,32 @@ impl MsgSender {
}
}

/// Starts a new `MsgSender` for the given entity path, and fill it with the contents of the
/// passed-in [`Archetype`].
///
/// WARNING: This is an experimental feature!
pub fn from_archetype(
ent_path: impl Into<EntityPath>,
arch: &impl Archetype,
) -> Result<Self, MsgSenderError> {
let serialized = arch.to_arrow();

let mut this = Self::new(ent_path);
for (field, array) in serialized {
// NOTE: Unreachable, a top-level Field will always be a component, and thus an
// extension.
let DataType::Extension(_, _, legacy_fqname) = field.data_type else { unreachable!() };
this = this.with_cell(DataCell::from_arrow(
// NOTE: Unwrapping is safe as we always include the legacy fqname into the Field's
// metadata while migrating towards HOPE.
legacy_fqname.as_deref().unwrap().into(),
array,
))?;
}

Ok(this)
}

/// Read the file at the given path and log it.
///
/// Supported file extensions are:
Expand Down
2 changes: 1 addition & 1 deletion crates/re_types/source_hash.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This is a sha256 hash for all direct and indirect dependencies of this crate's build script.
# It can be safely removed at anytime to force the build script to run again.
# Check out build.rs to see how it's computed.
128cd542f3f9e6cf3b2a44aeb022cd5f3ad819b00ce5371eeb311300f3e9a7f1
afc01539cb778ef699e8cef27436420fe8dc4ee078fdd56d874e2409b3749d88
168 changes: 140 additions & 28 deletions crates/re_types/src/archetypes/fuzzy.rs

Large diffs are not rendered by default.

48 changes: 40 additions & 8 deletions crates/re_types/src/archetypes/points2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ impl crate::Archetype for Points2D {
let array =
<crate::components::Point2D>::try_to_arrow(self.points.iter(), None);
array.map(|array| {
let datatype = array.data_type().clone();
let datatype = ::arrow2::datatypes::DataType::Extension(
"rerun.components.Point2D".into(),
Box::new(array.data_type().clone()),
Some("rerun.point2d".into()),
);
(
::arrow2::datatypes::Field::new("points", datatype, false),
array,
Expand All @@ -126,7 +130,11 @@ impl crate::Archetype for Points2D {
.map(|many| {
let array = <crate::components::Radius>::try_to_arrow(many.iter(), None);
array.map(|array| {
let datatype = array.data_type().clone();
let datatype = ::arrow2::datatypes::DataType::Extension(
"rerun.components.Radius".into(),
Box::new(array.data_type().clone()),
Some("rerun.radius".into()),
);
(
::arrow2::datatypes::Field::new("radii", datatype, false),
array,
Expand All @@ -141,7 +149,11 @@ impl crate::Archetype for Points2D {
.map(|many| {
let array = <crate::components::Color>::try_to_arrow(many.iter(), None);
array.map(|array| {
let datatype = array.data_type().clone();
let datatype = ::arrow2::datatypes::DataType::Extension(
"rerun.components.Color".into(),
Box::new(array.data_type().clone()),
Some("rerun.colorrgba".into()),
);
(
::arrow2::datatypes::Field::new("colors", datatype, false),
array,
Expand All @@ -156,7 +168,11 @@ impl crate::Archetype for Points2D {
.map(|many| {
let array = <crate::components::Label>::try_to_arrow(many.iter(), None);
array.map(|array| {
let datatype = array.data_type().clone();
let datatype = ::arrow2::datatypes::DataType::Extension(
"rerun.components.Label".into(),
Box::new(array.data_type().clone()),
Some("rerun.label".into()),
);
(
::arrow2::datatypes::Field::new("labels", datatype, false),
array,
Expand All @@ -171,7 +187,11 @@ impl crate::Archetype for Points2D {
.map(|single| {
let array = <crate::components::DrawOrder>::try_to_arrow([single], None);
array.map(|array| {
let datatype = array.data_type().clone();
let datatype = ::arrow2::datatypes::DataType::Extension(
"rerun.components.DrawOrder".into(),
Box::new(array.data_type().clone()),
Some("rerun.draw_order".into()),
);
(
::arrow2::datatypes::Field::new("draw_order", datatype, false),
array,
Expand All @@ -186,7 +206,11 @@ impl crate::Archetype for Points2D {
.map(|many| {
let array = <crate::components::ClassId>::try_to_arrow(many.iter(), None);
array.map(|array| {
let datatype = array.data_type().clone();
let datatype = ::arrow2::datatypes::DataType::Extension(
"rerun.components.ClassId".into(),
Box::new(array.data_type().clone()),
Some("rerun.class_id".into()),
);
(
::arrow2::datatypes::Field::new("class_ids", datatype, false),
array,
Expand All @@ -202,7 +226,11 @@ impl crate::Archetype for Points2D {
let array =
<crate::components::KeypointId>::try_to_arrow(many.iter(), None);
array.map(|array| {
let datatype = array.data_type().clone();
let datatype = ::arrow2::datatypes::DataType::Extension(
"rerun.components.KeypointId".into(),
Box::new(array.data_type().clone()),
Some("rerun.keypoint_id".into()),
);
(
::arrow2::datatypes::Field::new("keypoint_ids", datatype, false),
array,
Expand All @@ -218,7 +246,11 @@ impl crate::Archetype for Points2D {
let array =
<crate::components::InstanceKey>::try_to_arrow(many.iter(), None);
array.map(|array| {
let datatype = array.data_type().clone();
let datatype = ::arrow2::datatypes::DataType::Extension(
"rerun.components.InstanceKey".into(),
Box::new(array.data_type().clone()),
Some("rerun.instance_key".into()),
);
(
::arrow2::datatypes::Field::new("instance_keys", datatype, false),
array,
Expand Down
8 changes: 3 additions & 5 deletions crates/re_types/src/components/class_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ impl crate::Component for ClassId {
#[inline]
fn to_arrow_datatype() -> arrow2::datatypes::DataType {
use ::arrow2::datatypes::*;
DataType::Extension(
"rerun.components.ClassId".to_owned(),
Box::new(DataType::UInt16),
None,
)
DataType::UInt16
}

#[allow(unused_imports, clippy::wildcard_imports)]
Expand Down Expand Up @@ -79,6 +75,8 @@ impl crate::Component for ClassId {
Box::new(DataType::UInt16),
None,
)
.to_logical_type()
.clone()
},
data0.into_iter().map(|v| v.unwrap_or_default()).collect(),
data0_bitmap,
Expand Down
8 changes: 3 additions & 5 deletions crates/re_types/src/components/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ impl crate::Component for Color {
#[inline]
fn to_arrow_datatype() -> arrow2::datatypes::DataType {
use ::arrow2::datatypes::*;
DataType::Extension(
"rerun.components.Color".to_owned(),
Box::new(DataType::UInt32),
None,
)
DataType::UInt32
}

#[allow(unused_imports, clippy::wildcard_imports)]
Expand Down Expand Up @@ -89,6 +85,8 @@ impl crate::Component for Color {
Box::new(DataType::UInt32),
None,
)
.to_logical_type()
.clone()
},
data0.into_iter().map(|v| v.unwrap_or_default()).collect(),
data0_bitmap,
Expand Down
8 changes: 3 additions & 5 deletions crates/re_types/src/components/draw_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ impl crate::Component for DrawOrder {
#[inline]
fn to_arrow_datatype() -> arrow2::datatypes::DataType {
use ::arrow2::datatypes::*;
DataType::Extension(
"rerun.components.DrawOrder".to_owned(),
Box::new(DataType::Float32),
None,
)
DataType::Float32
}

#[allow(unused_imports, clippy::wildcard_imports)]
Expand Down Expand Up @@ -84,6 +80,8 @@ impl crate::Component for DrawOrder {
Box::new(DataType::Float32),
None,
)
.to_logical_type()
.clone()
},
data0.into_iter().map(|v| v.unwrap_or_default()).collect(),
data0_bitmap,
Expand Down
Loading