Expand description
Serialize / Deserialize DataFusion Primitive Types to bytes
This crate provides support for serializing and deserializing the following structures to and from bytes:
Internally, this crate is implemented by converting the common types to protocol buffers using prost.
§Version Compatibility
The serialized form are not guaranteed to be compatible across DataFusion versions. A plan serialized with one version of DataFusion may not be able to deserialized with a different version.
§See Also
The binary format created by this crate supports the full range of DataFusion plans, but is DataFusion specific. See datafusion-substrait for a crate which can encode many DataFusion plans using the substrait.io standard.
§Example: Serializing ScalarValue
s
// Create a new ScalarValue
let val = ScalarValue::UInt64(Some(3));
let mut buffer = BytesMut::new();
let protobuf: protobuf_common::ScalarValue = match val {
ScalarValue::UInt64(Some(val)) => {
protobuf_common::ScalarValue{value: Some(protobuf_common::scalar_value::Value::Uint64Value(val))}
}
_ => unreachable!(),
};
protobuf.encode(&mut buffer)
.map_err(|e| plan_datafusion_err!("Error encoding protobuf as bytes: {e}"))?;
// Convert it to bytes (for sending over the network, etc.)
let bytes: Bytes = buffer.into();
let protobuf = protobuf_common::ScalarValue::decode(bytes).map_err(|e| plan_datafusion_err!("Error decoding ScalarValue as protobuf: {e}"))?;
// Decode bytes from somewhere (over network, etc.) back to ScalarValue
let decoded_val: ScalarValue = match protobuf.value {
Some(protobuf_common::scalar_value::Value::Uint64Value(val)) => ScalarValue::UInt64(Some(val)),
_ => unreachable!(),
};
assert_eq!(val, decoded_val);
Re-exports§
pub use from_proto::Error as FromProtoError;
pub use generated::datafusion_proto_common as protobuf_common;
pub use to_proto::Error as ToProtoError;
pub use generated::datafusion_proto_common::*;