Skip to content

Conversation

@andygrove
Copy link
Member

@andygrove andygrove commented May 28, 2022

Which issue does this PR close?

Closes #2630

Rationale for this change

I want to be able to serialize logical plans.

What changes are included in this PR?

  • Add LogicalPlan types to datafusion.proto (copied from Ballista)
  • Add LogicalPlan serde code (copied from Ballista)
  • Expose via API
  • Write tests
  • Update documentation

Example:

let ctx = SessionContext::new();
ctx.register_csv("t1", "testdata/test.csv", CsvReadOptions::default())
    .await
    .unwrap();
let plan = ctx.table("t1").unwrap().to_logical_plan().unwrap();
let bytes = logical_plan_to_bytes(&plan).unwrap();
let logical_round_trip = logical_plan_from_bytes(&bytes, &ctx).unwrap();
assert_eq!(format!("{:?}", plan), format!("{:?}", logical_round_trip));

Are there any user-facing changes?

New APIs

Does this PR break compatibility with Ballista?

No, but I plan on updating Ballista soon to use these new APIs.

@andygrove andygrove self-assigned this May 28, 2022
@andygrove andygrove changed the title WIP: Implement LogicalPlan serde in datafusion-proto Implement LogicalPlan serde in datafusion-proto May 28, 2022
@andygrove andygrove marked this pull request as ready for review May 28, 2022 16:40
@andygrove andygrove requested a review from alamb May 28, 2022 16:43
@github-actions github-actions bot added the core Core DataFusion crate label May 28, 2022
@andygrove
Copy link
Member Author

@thinkharderdev @yahoNanJing fyi

}
}

/// Serialize a LogicalPlan as bytes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it is time to think about a slightly more encapsulated API, something that would allow

  let bytes = PlanSerializer::new()
    .with_extension_codec(&extension_codec)
   .serialize()?;

Rather than having two separate free functions 🤷

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I had been thinking about this too and we will need a unified API to implement subquery support (because expressions now reference plans) so I think we can make this API change as part of #2640

pub mod to_proto;

#[cfg(doctest)]
doc_comment::doctest!("../README.md", readme_example_test);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

#[tokio::test]
async fn roundtrip_logical_plan() -> Result<(), DataFusionError> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to add a test that uses an extension codec, to prevent future regressions

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test based on the TopK extension codec from Ballista

@andygrove andygrove merged commit a4c3a52 into apache:master May 29, 2022
@andygrove andygrove deleted the logical-plan-proto branch May 29, 2022 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add logical plan support to datafusion-proto

4 participants