1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// SPDX-License-Identifier: Apache-2.0
//! [Substrait]: Cross-Language Serialization for Relational Algebra
//!
//! # Serialization and deserialization
//!
//! This crate provides generated types to serialize and deserialize Substrait
//! data.
//!
//! ## Protobuf
//!
//! Protobuf serialization and deserialization are provided via [prost] in the
//! [proto] module.
//!
//! ### Example
//!
//! #### Serialize and deserialize a plan
//! ```rust
//! # fn main() -> Result<(), prost::DecodeError> {
//! use prost::Message;
//! use substrait::proto::Plan;
//!
//! let plan = Plan::default();
//!
//! // Serialize the plan
//! let encoded = plan.encode_to_vec();
//!
//! // Deserialize the buffer to a Plan
//! let decoded = Plan::decode(encoded.as_slice())?;
//!
//! assert_eq!(plan, decoded);
//! # Ok(()) }
//! ```
//!
//! ### Serde support
//!
//! The `serde` feature generates serde implementations that match the [Protobuf JSON Mapping]
//! via [pbjson].
//!
//! ##### Example
//! ###### Deserialize a plan version using the `serde` feature
//! ```rust
//! # fn main() -> Result<(), serde_json::Error> {
//! # #[cfg(feature="serde")] {
//! use substrait::proto::Version;
//!
//! let version_json = r#"{
//! "minorNumber": 21
//! }"#;
//!
//! let version = serde_json::from_str::<Version>(version_json)?;
//! assert_eq!(
//! version,
//! Version {
//! minor_number: 21,
//! ..Default::default()
//! }
//! );
//! # } Ok(()) }
//! ```
//!
//! ## Text
//!
//! Substrait defines a YAML schema for extensions. Types with serialization and
//! deserialization support for these are provided via [typify] in the [text]
//! module.
//!
//! ### Example
//!
//! #### Read a simple extension
//! ```rust
//! # #[cfg(feature="extensions")]
//! # fn main() -> Result<(), serde_yaml::Error> {
//! use substrait::text::simple_extensions::SimpleExtensions;
//!
//! let simple_extension_yaml = r#"
//! %YAML 1.2
//! ---
//! urn: extension:substrait-rs:add-example
//! scalar_functions:
//! -
//! name: "add"
//! description: "Add two values."
//! impls:
//! - args:
//! - name: x
//! value: i8
//! - name: y
//! value: i8
//! options:
//! overflow:
//! values: [ SILENT, SATURATE, ERROR ]
//! return: i8
//! "#;
//!
//! let simple_extension = serde_yaml::from_str::<SimpleExtensions>(simple_extension_yaml)?;
//!
//! assert_eq!(simple_extension.urn, "extension:substrait-rs:add-example");
//! assert_eq!(simple_extension.scalar_functions.len(), 1);
//! assert_eq!(simple_extension.scalar_functions[0].name, "add");
//! # Ok(()) }
//! # #[cfg(not(feature="extensions"))]
//! # fn main() {}
//! ```
//!
//! [pbjson]: https://docs.rs/pbjson
//! [Protobuf JSON Mapping]:
//! https://developers.google.com/protocol-buffers/docs/proto3#json
//! [Substrait]: https://substrait.io
//! [typify]: https://docs.rs/typify