Skip to main content

substrait/
proto.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Generated types for the protobuf `substrait` package.
4//!
5//! These types are provided by the [`substrait-prost`](https://docs.rs/substrait-prost)
6//! crate and re-exported here. This includes the [`extensions`] submodule and,
7//! with the `embed-descriptor` feature, the `FILE_DESCRIPTOR_SET` constant.
8
9pub use substrait_prost::*;
10
11#[cfg(test)]
12mod tests {
13    #[cfg(feature = "serde")]
14    #[test]
15    fn pbjson_serde() -> Result<(), Box<dyn std::error::Error>> {
16        let plan = serde_json::from_str::<super::Plan>(
17            r#"{
18  "version": { "minorNumber": 75, "producer": "substrait-rs" },
19  "extensionUrns": [
20    {
21      "extensionUrnAnchor": 1,
22      "urn": "extension:io.substrait:functions_string"
23    }
24  ]
25}"#,
26        )?;
27        assert_eq!(
28            plan.version,
29            Some(super::Version {
30                minor_number: 75,
31                producer: "substrait-rs".into(),
32                ..Default::default()
33            })
34        );
35        assert_eq!(plan.extension_urns.len(), 1);
36        Ok(())
37    }
38
39    #[cfg(feature = "serde")]
40    #[test]
41    fn forward_compatible_unknown_fields() -> Result<(), Box<dyn std::error::Error>> {
42        // Test that unknown fields are ignored for forward compatibility
43        let plan = serde_json::from_str::<super::Plan>(
44            r#"{
45  "version": { "minorNumber": 75, "producer": "substrait-rs" },
46  "unknownField": "this field doesn't exist in the proto",
47  "anotherUnknownField": {"nested": "data"},
48  "extensionUrns": [
49    {
50      "extensionUrnAnchor": 1,
51      "urn": "extension:io.substrait:functions_string",
52      "futureField": "should be ignored"
53    }
54  ]
55}"#,
56        )?;
57        assert_eq!(
58            plan.version,
59            Some(super::Version {
60                minor_number: 75,
61                producer: "substrait-rs".into(),
62                ..Default::default()
63            })
64        );
65        assert_eq!(plan.extension_urns.len(), 1);
66        Ok(())
67    }
68
69    #[cfg(feature = "embed-descriptor")]
70    #[test]
71    fn file_descriptor_set_is_valid() {
72        use prost::Message;
73        let fds = prost_types::FileDescriptorSet::decode(super::FILE_DESCRIPTOR_SET).unwrap();
74        assert!(
75            fds.file.iter().any(|f| f.package() == "substrait"),
76            "expected substrait package in file descriptor set"
77        );
78    }
79}