From 670812d44f7f5a5579acd6b26979375c794654a2 Mon Sep 17 00:00:00 2001 From: Clement Rey Date: Fri, 7 Jul 2023 16:30:57 +0200 Subject: [PATCH] Don't use builtin `required` anymore, introduce `nullable` instead (#2619) Fixes #2525 Closes #2524 --- ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/2619) (if applicable) - [PR Build Summary](https://build.rerun.io/pr/2619) - [Docs preview](https://rerun.io/preview/pr%3Acmc%2Fattr_nullable/docs) - [Examples preview](https://rerun.io/preview/pr%3Acmc%2Fattr_nullable/examples) --- .../re_types/definitions/fbs/attributes.fbs | 8 ++ .../definitions/rerun/archetypes/points2d.fbs | 16 +-- .../definitions/rerun/components/label.fbs | 2 +- .../rerun/testing/archetypes/fuzzy.fbs | 104 +++++++++--------- .../rerun/testing/components/fuzzy.fbs | 26 ++--- .../rerun/testing/datatypes/fuzzy.fbs | 18 +-- crates/re_types/source_hash.txt | 2 +- crates/re_types/src/components/fuzzy.rs | 18 +-- crates/re_types/src/datatypes/fuzzy.rs | 31 ++++-- crates/re_types/tests/fuzzy.rs | 10 +- crates/re_types_builder/src/lib.rs | 1 + crates/re_types_builder/src/objects.rs | 12 +- .../rerun/_rerun2/components/fuzzy.py | 2 +- .../rerun/_rerun2/datatypes/fuzzy.py | 9 +- 14 files changed, 141 insertions(+), 118 deletions(-) diff --git a/crates/re_types/definitions/fbs/attributes.fbs b/crates/re_types/definitions/fbs/attributes.fbs index d8b50532e3d5..48a33ecf7c45 100644 --- a/crates/re_types/definitions/fbs/attributes.fbs +++ b/crates/re_types/definitions/fbs/attributes.fbs @@ -30,3 +30,11 @@ attribute "order"; /// table when defining a union, cannot put arrays (as opposed to vectors) into tables, etc) that /// do not apply in our case. attribute "transparent"; + +/// If specified on a field, the field becomes nullable, which affects both its native as well as +/// its arrow datatypes. +/// +/// NOTE: We do not use flatbuffers' builtin `required` attribute because A) it has many +/// limitations that do not make sense for our use case and B) our overall data model is built +/// around the idea of nullability, rather than requirements (i.e. the exact opposite). +attribute "nullable"; diff --git a/crates/re_types/definitions/rerun/archetypes/points2d.fbs b/crates/re_types/definitions/rerun/archetypes/points2d.fbs index d16250144acd..9d7dd636ec8c 100644 --- a/crates/re_types/definitions/rerun/archetypes/points2d.fbs +++ b/crates/re_types/definitions/rerun/archetypes/points2d.fbs @@ -34,34 +34,34 @@ table Points2D ( // --- Required --- /// All the actual 2D points that make up the point cloud. - points: [rerun.components.Point2D] ("attr.rerun.component_required", required, order: 1000); + points: [rerun.components.Point2D] ("attr.rerun.component_required", order: 1000); // --- Recommended --- /// Optional radii for the points, effectively turning them into circles. - radii: [rerun.components.Radius] ("attr.rerun.component_recommended", order: 2000); + radii: [rerun.components.Radius] ("attr.rerun.component_recommended", nullable, order: 2000); /// Optional colors for the points. /// /// \python The colors are interpreted as RGB or RGBA in sRGB gamma-space, /// \python As either 0-1 floats or 0-255 integers, with separate alpha. - colors: [rerun.components.Color] ("attr.rerun.component_recommended", order: 2100); + colors: [rerun.components.Color] ("attr.rerun.component_recommended", nullable, order: 2100); // --- Optional --- /// Optional text labels for the points. - labels: [rerun.components.Label] ("attr.rerun.component_optional", order: 3000); + labels: [rerun.components.Label] ("attr.rerun.component_optional", nullable, order: 3000); /// An optional floating point value that specifies the 2D drawing order. /// Objects with higher values are drawn on top of those with lower values. /// /// The default for 2D points is 30.0. - draw_order: rerun.components.DrawOrder ("attr.rerun.component_optional", order: 3100); + draw_order: rerun.components.DrawOrder ("attr.rerun.component_optional", nullable, order: 3100); /// Optional class Ids for the points. /// /// The class ID provides colors and labels if not specified explicitly. - class_ids: [rerun.components.ClassId] ("attr.rerun.component_optional", order: 3200); + class_ids: [rerun.components.ClassId] ("attr.rerun.component_optional", nullable, order: 3200); /// Optional keypoint IDs for the points, identifying them within a class. /// @@ -71,8 +71,8 @@ table Points2D ( /// with `class_id`). /// E.g. the classification might be 'Person' and the keypoints refer to joints on a /// detected skeleton. - keypoint_ids: [rerun.components.KeypointId] ("attr.rerun.component_optional", order: 3300); + keypoint_ids: [rerun.components.KeypointId] ("attr.rerun.component_optional", nullable, order: 3300); /// Unique identifiers for each individual point in the batch. - instance_keys: [rerun.components.InstanceKey] ("attr.rerun.component_optional", order: 3400); + instance_keys: [rerun.components.InstanceKey] ("attr.rerun.component_optional", nullable, order: 3400); } diff --git a/crates/re_types/definitions/rerun/components/label.fbs b/crates/re_types/definitions/rerun/components/label.fbs index e0c4497264a0..f8de710a7157 100644 --- a/crates/re_types/definitions/rerun/components/label.fbs +++ b/crates/re_types/definitions/rerun/components/label.fbs @@ -19,5 +19,5 @@ table Label ( "attr.rust.tuple_struct", order: 100 ) { - value: string (required, order: 100); + value: string (order: 100); } diff --git a/crates/re_types/definitions/rerun/testing/archetypes/fuzzy.fbs b/crates/re_types/definitions/rerun/testing/archetypes/fuzzy.fbs index 913ff36b497c..50cb30970122 100644 --- a/crates/re_types/definitions/rerun/testing/archetypes/fuzzy.fbs +++ b/crates/re_types/definitions/rerun/testing/archetypes/fuzzy.fbs @@ -15,60 +15,60 @@ table AffixFuzzer1 ( "attr.rust.derive": "PartialEq", order: 100 ) { - fuzz1001: rerun.testing.components.AffixFuzzer1 ("attr.rerun.component_required", required, order: 1001); - fuzz1002: rerun.testing.components.AffixFuzzer2 ("attr.rerun.component_required", required, order: 1002); - fuzz1003: rerun.testing.components.AffixFuzzer3 ("attr.rerun.component_required", required, order: 1003); - fuzz1004: rerun.testing.components.AffixFuzzer4 ("attr.rerun.component_required", required, order: 1004); - fuzz1005: rerun.testing.components.AffixFuzzer5 ("attr.rerun.component_required", required, order: 1005); - fuzz1006: rerun.testing.components.AffixFuzzer6 ("attr.rerun.component_required", required, order: 1006); - fuzz1007: rerun.testing.components.AffixFuzzer7 ("attr.rerun.component_required", required, order: 1007); - fuzz1008: rerun.testing.components.AffixFuzzer8 ("attr.rerun.component_required", required, order: 1008); - fuzz1009: rerun.testing.components.AffixFuzzer9 ("attr.rerun.component_required", required, order: 1009); - fuzz1010: rerun.testing.components.AffixFuzzer10 ("attr.rerun.component_required", required, order: 1010); - fuzz1011: rerun.testing.components.AffixFuzzer11 ("attr.rerun.component_required", required, order: 1011); - fuzz1012: rerun.testing.components.AffixFuzzer12 ("attr.rerun.component_required", required, order: 1012); - fuzz1013: rerun.testing.components.AffixFuzzer13 ("attr.rerun.component_required", required, order: 1013); + fuzz1001: rerun.testing.components.AffixFuzzer1 ("attr.rerun.component_required", order: 1001); + fuzz1002: rerun.testing.components.AffixFuzzer2 ("attr.rerun.component_required", order: 1002); + fuzz1003: rerun.testing.components.AffixFuzzer3 ("attr.rerun.component_required", order: 1003); + fuzz1004: rerun.testing.components.AffixFuzzer4 ("attr.rerun.component_required", order: 1004); + fuzz1005: rerun.testing.components.AffixFuzzer5 ("attr.rerun.component_required", order: 1005); + fuzz1006: rerun.testing.components.AffixFuzzer6 ("attr.rerun.component_required", order: 1006); + fuzz1007: rerun.testing.components.AffixFuzzer7 ("attr.rerun.component_required", order: 1007); + fuzz1008: rerun.testing.components.AffixFuzzer8 ("attr.rerun.component_required", order: 1008); + fuzz1009: rerun.testing.components.AffixFuzzer9 ("attr.rerun.component_required", order: 1009); + fuzz1010: rerun.testing.components.AffixFuzzer10 ("attr.rerun.component_required", order: 1010); + fuzz1011: rerun.testing.components.AffixFuzzer11 ("attr.rerun.component_required", order: 1011); + fuzz1012: rerun.testing.components.AffixFuzzer12 ("attr.rerun.component_required", order: 1012); + fuzz1013: rerun.testing.components.AffixFuzzer13 ("attr.rerun.component_required", order: 1013); - fuzz1101: [rerun.testing.components.AffixFuzzer1] ("attr.rerun.component_required", required, order: 1101); - fuzz1102: [rerun.testing.components.AffixFuzzer2] ("attr.rerun.component_required", required, order: 1102); - fuzz1103: [rerun.testing.components.AffixFuzzer3] ("attr.rerun.component_required", required, order: 1103); - fuzz1104: [rerun.testing.components.AffixFuzzer4] ("attr.rerun.component_required", required, order: 1104); - fuzz1105: [rerun.testing.components.AffixFuzzer5] ("attr.rerun.component_required", required, order: 1105); - fuzz1106: [rerun.testing.components.AffixFuzzer6] ("attr.rerun.component_required", required, order: 1106); - fuzz1107: [rerun.testing.components.AffixFuzzer7] ("attr.rerun.component_required", required, order: 1107); - fuzz1108: [rerun.testing.components.AffixFuzzer8] ("attr.rerun.component_required", required, order: 1108); - fuzz1109: [rerun.testing.components.AffixFuzzer9] ("attr.rerun.component_required", required, order: 1109); - fuzz1110: [rerun.testing.components.AffixFuzzer10] ("attr.rerun.component_required", required, order: 1110); - fuzz1111: [rerun.testing.components.AffixFuzzer11] ("attr.rerun.component_required", required, order: 1111); - fuzz1112: [rerun.testing.components.AffixFuzzer12] ("attr.rerun.component_required", required, order: 1112); - fuzz1113: [rerun.testing.components.AffixFuzzer13] ("attr.rerun.component_required", required, order: 1113); + fuzz1101: [rerun.testing.components.AffixFuzzer1] ("attr.rerun.component_required", order: 1101); + fuzz1102: [rerun.testing.components.AffixFuzzer2] ("attr.rerun.component_required", order: 1102); + fuzz1103: [rerun.testing.components.AffixFuzzer3] ("attr.rerun.component_required", order: 1103); + fuzz1104: [rerun.testing.components.AffixFuzzer4] ("attr.rerun.component_required", order: 1104); + fuzz1105: [rerun.testing.components.AffixFuzzer5] ("attr.rerun.component_required", order: 1105); + fuzz1106: [rerun.testing.components.AffixFuzzer6] ("attr.rerun.component_required", order: 1106); + fuzz1107: [rerun.testing.components.AffixFuzzer7] ("attr.rerun.component_required", order: 1107); + fuzz1108: [rerun.testing.components.AffixFuzzer8] ("attr.rerun.component_required", order: 1108); + fuzz1109: [rerun.testing.components.AffixFuzzer9] ("attr.rerun.component_required", order: 1109); + fuzz1110: [rerun.testing.components.AffixFuzzer10] ("attr.rerun.component_required", order: 1110); + fuzz1111: [rerun.testing.components.AffixFuzzer11] ("attr.rerun.component_required", order: 1111); + fuzz1112: [rerun.testing.components.AffixFuzzer12] ("attr.rerun.component_required", order: 1112); + fuzz1113: [rerun.testing.components.AffixFuzzer13] ("attr.rerun.component_required", order: 1113); - fuzz2001: rerun.testing.components.AffixFuzzer1 ("attr.rerun.component_optional", order: 2001); - fuzz2002: rerun.testing.components.AffixFuzzer2 ("attr.rerun.component_optional", order: 2002); - fuzz2003: rerun.testing.components.AffixFuzzer3 ("attr.rerun.component_optional", order: 2003); - fuzz2004: rerun.testing.components.AffixFuzzer4 ("attr.rerun.component_optional", order: 2004); - fuzz2005: rerun.testing.components.AffixFuzzer5 ("attr.rerun.component_optional", order: 2005); - fuzz2006: rerun.testing.components.AffixFuzzer6 ("attr.rerun.component_optional", order: 2006); - fuzz2007: rerun.testing.components.AffixFuzzer7 ("attr.rerun.component_optional", order: 2007); - fuzz2008: rerun.testing.components.AffixFuzzer8 ("attr.rerun.component_optional", order: 2008); - fuzz2009: rerun.testing.components.AffixFuzzer9 ("attr.rerun.component_optional", order: 2009); - fuzz2010: rerun.testing.components.AffixFuzzer10 ("attr.rerun.component_optional", order: 2010); - fuzz2011: rerun.testing.components.AffixFuzzer11 ("attr.rerun.component_optional", order: 2011); - fuzz2012: rerun.testing.components.AffixFuzzer12 ("attr.rerun.component_optional", order: 2012); - fuzz2013: rerun.testing.components.AffixFuzzer13 ("attr.rerun.component_optional", order: 2013); + fuzz2001: rerun.testing.components.AffixFuzzer1 ("attr.rerun.component_optional", nullable, order: 2001); + fuzz2002: rerun.testing.components.AffixFuzzer2 ("attr.rerun.component_optional", nullable, order: 2002); + fuzz2003: rerun.testing.components.AffixFuzzer3 ("attr.rerun.component_optional", nullable, order: 2003); + fuzz2004: rerun.testing.components.AffixFuzzer4 ("attr.rerun.component_optional", nullable, order: 2004); + fuzz2005: rerun.testing.components.AffixFuzzer5 ("attr.rerun.component_optional", nullable, order: 2005); + fuzz2006: rerun.testing.components.AffixFuzzer6 ("attr.rerun.component_optional", nullable, order: 2006); + fuzz2007: rerun.testing.components.AffixFuzzer7 ("attr.rerun.component_optional", nullable, order: 2007); + fuzz2008: rerun.testing.components.AffixFuzzer8 ("attr.rerun.component_optional", nullable, order: 2008); + fuzz2009: rerun.testing.components.AffixFuzzer9 ("attr.rerun.component_optional", nullable, order: 2009); + fuzz2010: rerun.testing.components.AffixFuzzer10 ("attr.rerun.component_optional", nullable, order: 2010); + fuzz2011: rerun.testing.components.AffixFuzzer11 ("attr.rerun.component_optional", nullable, order: 2011); + fuzz2012: rerun.testing.components.AffixFuzzer12 ("attr.rerun.component_optional", nullable, order: 2012); + fuzz2013: rerun.testing.components.AffixFuzzer13 ("attr.rerun.component_optional", nullable, order: 2013); - fuzz2101: [rerun.testing.components.AffixFuzzer1] ("attr.rerun.component_optional", order: 2101); - fuzz2102: [rerun.testing.components.AffixFuzzer2] ("attr.rerun.component_optional", order: 2102); - fuzz2103: [rerun.testing.components.AffixFuzzer3] ("attr.rerun.component_optional", order: 2103); - fuzz2104: [rerun.testing.components.AffixFuzzer4] ("attr.rerun.component_optional", order: 2104); - fuzz2105: [rerun.testing.components.AffixFuzzer5] ("attr.rerun.component_optional", order: 2105); - fuzz2106: [rerun.testing.components.AffixFuzzer6] ("attr.rerun.component_optional", order: 2106); - fuzz2107: [rerun.testing.components.AffixFuzzer7] ("attr.rerun.component_optional", order: 2107); - fuzz2108: [rerun.testing.components.AffixFuzzer8] ("attr.rerun.component_optional", order: 2108); - fuzz2109: [rerun.testing.components.AffixFuzzer9] ("attr.rerun.component_optional", order: 2109); - fuzz2110: [rerun.testing.components.AffixFuzzer10] ("attr.rerun.component_optional", order: 2110); - fuzz2111: [rerun.testing.components.AffixFuzzer11] ("attr.rerun.component_optional", order: 2111); - fuzz2112: [rerun.testing.components.AffixFuzzer12] ("attr.rerun.component_optional", order: 2112); - fuzz2113: [rerun.testing.components.AffixFuzzer13] ("attr.rerun.component_optional", order: 2113); + fuzz2101: [rerun.testing.components.AffixFuzzer1] ("attr.rerun.component_optional", nullable, order: 2101); + fuzz2102: [rerun.testing.components.AffixFuzzer2] ("attr.rerun.component_optional", nullable, order: 2102); + fuzz2103: [rerun.testing.components.AffixFuzzer3] ("attr.rerun.component_optional", nullable, order: 2103); + fuzz2104: [rerun.testing.components.AffixFuzzer4] ("attr.rerun.component_optional", nullable, order: 2104); + fuzz2105: [rerun.testing.components.AffixFuzzer5] ("attr.rerun.component_optional", nullable, order: 2105); + fuzz2106: [rerun.testing.components.AffixFuzzer6] ("attr.rerun.component_optional", nullable, order: 2106); + fuzz2107: [rerun.testing.components.AffixFuzzer7] ("attr.rerun.component_optional", nullable, order: 2107); + fuzz2108: [rerun.testing.components.AffixFuzzer8] ("attr.rerun.component_optional", nullable, order: 2108); + fuzz2109: [rerun.testing.components.AffixFuzzer9] ("attr.rerun.component_optional", nullable, order: 2109); + fuzz2110: [rerun.testing.components.AffixFuzzer10] ("attr.rerun.component_optional", nullable, order: 2110); + fuzz2111: [rerun.testing.components.AffixFuzzer11] ("attr.rerun.component_optional", nullable, order: 2111); + fuzz2112: [rerun.testing.components.AffixFuzzer12] ("attr.rerun.component_optional", nullable, order: 2112); + fuzz2113: [rerun.testing.components.AffixFuzzer13] ("attr.rerun.component_optional", nullable, order: 2113); } diff --git a/crates/re_types/definitions/rerun/testing/components/fuzzy.fbs b/crates/re_types/definitions/rerun/testing/components/fuzzy.fbs index da39e113548a..4ddf8697fde8 100644 --- a/crates/re_types/definitions/rerun/testing/components/fuzzy.fbs +++ b/crates/re_types/definitions/rerun/testing/components/fuzzy.fbs @@ -12,7 +12,7 @@ table AffixFuzzer1 ( "attr.rust.derive": "PartialEq", order: 100 ) { - single_required: rerun.testing.datatypes.AffixFuzzer1 (required, order: 101); + single_required: rerun.testing.datatypes.AffixFuzzer1 (order: 101); } table AffixFuzzer2 ( @@ -20,21 +20,21 @@ table AffixFuzzer2 ( "attr.rust.tuple_struct", order: 200 ) { - single_required: rerun.testing.datatypes.AffixFuzzer1 (required, order: 102); + single_required: rerun.testing.datatypes.AffixFuzzer1 (order: 102); } table AffixFuzzer3 ( "attr.rust.derive": "PartialEq", order: 300 ) { - single_required: rerun.testing.datatypes.AffixFuzzer1 (required, order: 103); + single_required: rerun.testing.datatypes.AffixFuzzer1 (order: 103); } table AffixFuzzer4 ( "attr.rust.derive": "PartialEq", order: 400 ) { - single_optional: rerun.testing.datatypes.AffixFuzzer1 (order: 104); + single_optional: rerun.testing.datatypes.AffixFuzzer1 (nullable, order: 104); } table AffixFuzzer5 ( @@ -42,63 +42,63 @@ table AffixFuzzer5 ( "attr.rust.tuple_struct", order: 500 ) { - single_optional: rerun.testing.datatypes.AffixFuzzer1 (order: 105); + single_optional: rerun.testing.datatypes.AffixFuzzer1 (nullable, order: 105); } table AffixFuzzer6 ( "attr.rust.derive": "PartialEq", order: 600 ) { - single_optional: rerun.testing.datatypes.AffixFuzzer1 (order: 106); + single_optional: rerun.testing.datatypes.AffixFuzzer1 (nullable, order: 106); } table AffixFuzzer7 ( "attr.rust.derive": "PartialEq", order: 700 ) { - many_optional: [rerun.testing.datatypes.AffixFuzzer1] (order: 107); + many_optional: [rerun.testing.datatypes.AffixFuzzer1] (nullable, order: 107); } table AffixFuzzer8 ( "attr.rust.derive": "PartialEq", order: 800 ) { - single_float_optional: float (order: 108); + single_float_optional: float (nullable, order: 108); } table AffixFuzzer9 ( "attr.rust.derive": "PartialEq, Eq", order: 900 ) { - single_string_required: string (required, order: 109); + single_string_required: string (order: 109); } table AffixFuzzer10 ( "attr.rust.derive": "PartialEq, Eq", order: 1000 ) { - single_string_optional: string (order: 110); + single_string_optional: string (nullable, order: 110); } table AffixFuzzer11 ( "attr.rust.derive": "PartialEq", order: 1100 ) { - many_floats_optional: [float] (order: 111); + many_floats_optional: [float] (nullable, order: 111); } table AffixFuzzer12 ( "attr.rust.derive": "PartialEq, Eq", order: 1200 ) { - many_strings_required: [string] (required, order: 112); + many_strings_required: [string] (order: 112); } table AffixFuzzer13 ( "attr.rust.derive": "PartialEq, Eq", order: 1300 ) { - many_strings_optional: [string] (order: 113); + many_strings_optional: [string] (nullable, order: 113); } // TODO(cmc): the ugly bug we need to take care of at some point diff --git a/crates/re_types/definitions/rerun/testing/datatypes/fuzzy.fbs b/crates/re_types/definitions/rerun/testing/datatypes/fuzzy.fbs index 3671982ecbfd..1948e0764493 100644 --- a/crates/re_types/definitions/rerun/testing/datatypes/fuzzy.fbs +++ b/crates/re_types/definitions/rerun/testing/datatypes/fuzzy.fbs @@ -26,14 +26,14 @@ table AffixFuzzer1 ( "attr.rust.derive": "PartialEq", order: 100 ) { - single_float_optional: float (order: 101); - single_string_required: string (order: 102, required); - single_string_optional: string (order: 103); - many_floats_optional: [float] (order: 104); - many_strings_required: [string] (order: 105, required); - many_strings_optional: [string] (order: 106); - flattened_scalar: VeryDeeplyFlattenedScalar (order: 107, required, transparent); - almost_flattened_scalar: SurprisinglyShallowScalar (order: 108, required, transparent); + single_float_optional: float (nullable, order: 101); + single_string_required: string (order: 102); + single_string_optional: string (nullable, order: 103); + many_floats_optional: [float] (nullable, order: 104); + many_strings_required: [string] (order: 105); + many_strings_optional: [string] (nullable, order: 106); + flattened_scalar: VeryDeeplyFlattenedScalar (order: 107, transparent); + almost_flattened_scalar: SurprisinglyShallowScalar (order: 108, transparent); } table AffixFuzzer2 ( @@ -42,5 +42,5 @@ table AffixFuzzer2 ( "attr.rust.tuple_struct", order: 200 ) { - single_float_optional: float (order: 101); + single_float_optional: float (nullable, order: 101); } diff --git a/crates/re_types/source_hash.txt b/crates/re_types/source_hash.txt index 28285ddc57a4..442b76b83ccf 100644 --- a/crates/re_types/source_hash.txt +++ b/crates/re_types/source_hash.txt @@ -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. -7dfe285eaa19872ddde875b16aa511da2b0e1f9fbeed723fa7a86920a2cc1738 \ No newline at end of file +b0b0d5d6d0f4131e52331303a2c2dfdfa11e03936e97242ef897c2b158979273 \ No newline at end of file diff --git a/crates/re_types/src/components/fuzzy.rs b/crates/re_types/src/components/fuzzy.rs index a1d1ef6d2105..92d070bd0bd5 100644 --- a/crates/re_types/src/components/fuzzy.rs +++ b/crates/re_types/src/components/fuzzy.rs @@ -101,7 +101,7 @@ impl crate::Component for AffixFuzzer1 { data_type: DataType::Struct(vec![Field { name: "value".to_owned(), data_type: DataType::Float32, - is_nullable: true, + is_nullable: false, metadata: [].into(), }]), is_nullable: false, @@ -258,7 +258,7 @@ impl crate::Component for AffixFuzzer2 { data_type: DataType::Struct(vec![Field { name: "value".to_owned(), data_type: DataType::Float32, - is_nullable: true, + is_nullable: false, metadata: [].into(), }]), is_nullable: false, @@ -417,7 +417,7 @@ impl crate::Component for AffixFuzzer3 { data_type: DataType::Struct(vec![Field { name: "value".to_owned(), data_type: DataType::Float32, - is_nullable: true, + is_nullable: false, metadata: [].into(), }]), is_nullable: false, @@ -576,7 +576,7 @@ impl crate::Component for AffixFuzzer4 { data_type: DataType::Struct(vec![Field { name: "value".to_owned(), data_type: DataType::Float32, - is_nullable: true, + is_nullable: false, metadata: [].into(), }]), is_nullable: false, @@ -731,7 +731,7 @@ impl crate::Component for AffixFuzzer5 { data_type: DataType::Struct(vec![Field { name: "value".to_owned(), data_type: DataType::Float32, - is_nullable: true, + is_nullable: false, metadata: [].into(), }]), is_nullable: false, @@ -888,7 +888,7 @@ impl crate::Component for AffixFuzzer6 { data_type: DataType::Struct(vec![Field { name: "value".to_owned(), data_type: DataType::Float32, - is_nullable: true, + is_nullable: false, metadata: [].into(), }]), is_nullable: false, @@ -1047,7 +1047,7 @@ impl crate::Component for AffixFuzzer7 { data_type: DataType::Struct(vec![Field { name: "value".to_owned(), data_type: DataType::Float32, - is_nullable: true, + is_nullable: false, metadata: [].into(), }]), is_nullable: false, @@ -1182,7 +1182,7 @@ impl crate::Component for AffixFuzzer7 { data_type: DataType::Struct(vec![Field { name: "value".to_owned(), data_type: DataType::Float32, - is_nullable: true, + is_nullable: false, metadata: [].into(), }]), is_nullable: false, @@ -1301,7 +1301,7 @@ impl crate::Component for AffixFuzzer7 { data_type: DataType::Struct(vec![Field { name: "value".to_owned(), data_type: DataType::Float32, - is_nullable: true, + is_nullable: false, metadata: [].into(), }]), is_nullable: false, diff --git a/crates/re_types/src/datatypes/fuzzy.rs b/crates/re_types/src/datatypes/fuzzy.rs index 567010f20a43..8498243f1c7d 100644 --- a/crates/re_types/src/datatypes/fuzzy.rs +++ b/crates/re_types/src/datatypes/fuzzy.rs @@ -11,7 +11,7 @@ #[derive(Debug, Clone, PartialEq)] pub struct FlattenedScalar { - pub value: Option, + pub value: f32, } impl<'a> From for ::std::borrow::Cow<'a, FlattenedScalar> { @@ -41,7 +41,7 @@ impl crate::Datatype for FlattenedScalar { DataType::Struct(vec![Field { name: "value".to_owned(), data_type: DataType::Float32, - is_nullable: true, + is_nullable: false, metadata: [].into(), }]) } @@ -84,13 +84,10 @@ impl crate::Datatype for FlattenedScalar { let (somes, value): (Vec<_>, Vec<_>) = data .iter() .map(|datum| { - let datum = datum - .as_ref() - .map(|datum| { - let Self { value, .. } = &**datum; - value.clone() - }) - .flatten(); + let datum = datum.as_ref().map(|datum| { + let Self { value, .. } = &**datum; + value.clone() + }); (datum.is_some(), datum) }) .unzip(); @@ -150,7 +147,19 @@ impl crate::Datatype for FlattenedScalar { }; ::itertools::izip!(value) .enumerate() - .map(|(i, (value))| is_valid(i).then(|| Ok(Self { value })).transpose()) + .map(|(i, (value))| { + is_valid(i) + .then(|| { + Ok(Self { + value: value.ok_or_else(|| { + crate::DeserializationError::MissingData { + datatype: data.data_type().clone(), + } + })?, + }) + }) + .transpose() + }) .collect::>>()? }) } @@ -255,7 +264,7 @@ impl crate::Datatype for AffixFuzzer1 { data_type: DataType::Struct(vec![Field { name: "value".to_owned(), data_type: DataType::Float32, - is_nullable: true, + is_nullable: false, metadata: [].into(), }]), is_nullable: false, diff --git a/crates/re_types/tests/fuzzy.rs b/crates/re_types/tests/fuzzy.rs index 37d78baf8950..3e471b2dbd7c 100644 --- a/crates/re_types/tests/fuzzy.rs +++ b/crates/re_types/tests/fuzzy.rs @@ -15,7 +15,7 @@ fn roundtrip() { many_strings_required: vec!["1".into(), "2".into()], many_strings_optional: Some(vec!["10".into(), "20".into()]), flattened_scalar: 42.0, - almost_flattened_scalar: re_types::datatypes::FlattenedScalar { value: Some(42.0) }, + almost_flattened_scalar: re_types::datatypes::FlattenedScalar { value: 42.0 }, }, }; @@ -27,7 +27,7 @@ fn roundtrip() { many_strings_required: vec!["3".into(), "4".into()], many_strings_optional: None, flattened_scalar: 43.0, - almost_flattened_scalar: re_types::datatypes::FlattenedScalar { value: Some(43.0) }, + almost_flattened_scalar: re_types::datatypes::FlattenedScalar { value: 43.0 }, }); let fuzzy3 = re_types::components::AffixFuzzer3 { @@ -39,7 +39,7 @@ fn roundtrip() { many_strings_required: vec!["5".into(), "6".into()], many_strings_optional: Some(vec!["50".into(), "60".into()]), flattened_scalar: 44.0, - almost_flattened_scalar: re_types::datatypes::FlattenedScalar { value: Some(44.0) }, + almost_flattened_scalar: re_types::datatypes::FlattenedScalar { value: 44.0 }, }, }; @@ -52,7 +52,7 @@ fn roundtrip() { many_strings_required: vec!["7".into(), "8".into()], many_strings_optional: None, flattened_scalar: 45.0, - almost_flattened_scalar: re_types::datatypes::FlattenedScalar { value: Some(45.0) }, + almost_flattened_scalar: re_types::datatypes::FlattenedScalar { value: 45.0 }, }), }; @@ -92,7 +92,7 @@ fn roundtrip() { many_strings_required: vec!["7".into(), "8".into()], many_strings_optional: None, flattened_scalar: 46.0, - almost_flattened_scalar: re_types::datatypes::FlattenedScalar { value: Some(46.0) }, + almost_flattened_scalar: re_types::datatypes::FlattenedScalar { value: 46.0 }, }]), }; diff --git a/crates/re_types_builder/src/lib.rs b/crates/re_types_builder/src/lib.rs index d1bfe57fea5c..0a89555d70d9 100644 --- a/crates/re_types_builder/src/lib.rs +++ b/crates/re_types_builder/src/lib.rs @@ -138,6 +138,7 @@ pub use self::objects::{ // --- Attributes --- +pub const ATTR_NULLABLE: &str = "nullable"; pub const ATTR_ORDER: &str = "order"; pub const ATTR_TRANSPARENT: &str = "transparent"; diff --git a/crates/re_types_builder/src/objects.rs b/crates/re_types_builder/src/objects.rs index 35d64b888e55..d07a0a564fce 100644 --- a/crates/re_types_builder/src/objects.rs +++ b/crates/re_types_builder/src/objects.rs @@ -616,9 +616,7 @@ pub struct ObjectField { /// The field's `order` attribute's value, which is always mandatory. pub order: u32, - /// Whether the field is required. - /// - /// Always true for IDL definitions using flatbuffers' `struct` type (as opposed to `table`). + /// Whether the field is nullable. pub is_nullable: bool, /// Whether the field is deprecated. @@ -662,7 +660,9 @@ impl ObjectField { let attrs = Attributes::from_raw_attrs(field.attributes()); let order = attrs.get::(&fqname, crate::ATTR_ORDER); - let is_nullable = !obj.is_struct() && !field.required(); + let is_nullable = attrs + .try_get::(&fqname, crate::ATTR_NULLABLE) + .is_some(); let is_deprecated = field.deprecated(); Self { @@ -714,8 +714,10 @@ impl ObjectField { let attrs = Attributes::from_raw_attrs(val.attributes()); let order = attrs.get::(&fqname, crate::ATTR_ORDER); + let is_nullable = attrs + .try_get::(&fqname, crate::ATTR_NULLABLE) + .is_some(); // TODO(cmc): not sure about this, but fbs unions are a bit weird that way - let is_nullable = false; let is_deprecated = false; Self { diff --git a/rerun_py/rerun_sdk/rerun/_rerun2/components/fuzzy.py b/rerun_py/rerun_sdk/rerun/_rerun2/components/fuzzy.py index 2ba67c186a25..734bce377269 100644 --- a/rerun_py/rerun_sdk/rerun/_rerun2/components/fuzzy.py +++ b/rerun_py/rerun_sdk/rerun/_rerun2/components/fuzzy.py @@ -212,7 +212,7 @@ def __init__(self) -> None: pa.field("flattened_scalar", pa.float32(), False, {}), pa.field( "almost_flattened_scalar", - pa.struct([pa.field("value", pa.float32(), True, {})]), + pa.struct([pa.field("value", pa.float32(), False, {})]), False, {}, ), diff --git a/rerun_py/rerun_sdk/rerun/_rerun2/datatypes/fuzzy.py b/rerun_py/rerun_sdk/rerun/_rerun2/datatypes/fuzzy.py index 88c3b03e587e..6a69a09ed79a 100644 --- a/rerun_py/rerun_sdk/rerun/_rerun2/datatypes/fuzzy.py +++ b/rerun_py/rerun_sdk/rerun/_rerun2/datatypes/fuzzy.py @@ -39,11 +39,14 @@ @define class FlattenedScalar: - value: float | None = field(default=None) + value: float = field() def __array__(self, dtype: npt.DTypeLike = None) -> npt.ArrayLike: return np.asarray(self.value, dtype=dtype) + def __float__(self) -> float: + return float(self.value) + FlattenedScalarLike = FlattenedScalar FlattenedScalarArrayLike = Union[ @@ -58,7 +61,7 @@ def __array__(self, dtype: npt.DTypeLike = None) -> npt.ArrayLike: class FlattenedScalarType(BaseExtensionType): def __init__(self) -> None: pa.ExtensionType.__init__( - self, pa.struct([pa.field("value", pa.float32(), True, {})]), "rerun.testing.datatypes.FlattenedScalar" + self, pa.struct([pa.field("value", pa.float32(), False, {})]), "rerun.testing.datatypes.FlattenedScalar" ) @@ -113,7 +116,7 @@ def __init__(self) -> None: pa.field("many_strings_optional", pa.list_(pa.field("item", pa.utf8(), True, {})), True, {}), pa.field("flattened_scalar", pa.float32(), False, {}), pa.field( - "almost_flattened_scalar", pa.struct([pa.field("value", pa.float32(), True, {})]), False, {} + "almost_flattened_scalar", pa.struct([pa.field("value", pa.float32(), False, {})]), False, {} ), ] ),