andygrove commented on code in PR #4892:
URL: https://github.com/apache/arrow-datafusion/pull/4892#discussion_r1072908462


##########
datafusion/substrait/src/serializer.rs:
##########
@@ -27,15 +27,20 @@ use std::fs::OpenOptions;
 use std::io::{Read, Write};
 
 pub async fn serialize(sql: &str, ctx: &SessionContext, path: &str) -> 
Result<()> {
+    let protobuf_out = serialize_bytes(sql, ctx).await;
+    let mut file = OpenOptions::new().create(true).write(true).open(path)?;
+    file.write_all(&protobuf_out.unwrap())?;
+    Ok(())
+}
+
+pub async fn serialize_bytes(sql: &str, ctx: &SessionContext) -> 
Result<Vec::<u8>> {
     let df = ctx.sql(sql).await?;
     let plan = df.into_optimized_plan()?;
     let proto = producer::to_substrait_plan(&plan)?;
 
     let mut protobuf_out = Vec::<u8>::new();
     proto.encode(&mut protobuf_out).unwrap();

Review Comment:
   Note that if we find that we need to add much code like this, then we can 
consider adding a `DataFusionError:Substrait` enum variant.
   
   ```suggestion
       proto.encode(&mut protobuf_out).map_err(|e| {
           DataFusionError::Internal(format!("Failed to encode substrait plan: 
{}", e))
       })?;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to