feat(core): add convenience methods Plan.toProto() and Plan.toJsonString()#381
feat(core): add convenience methods Plan.toProto() and Plan.toJsonString()#381nielspardon wants to merge 1 commit intosubstrait-io:mainfrom
Conversation
…ing() Signed-off-by: Niels Pardon <[email protected]>
I would push against this actually. Specifically, in your Thinking about the
My preference would be to not include this as it requires bringing in an extra dependency. Additionally, there's also lots of different ways to configure the JsonFormat used when marshalling, which will depend on your preferences. It is convenient, but it's not too difficult for end users to configure their own utility class for it. |
|
I do understand your concerns, however JSON is the recommended text serialization format of the Substrait specification according to this: https://substrait.io/serialization/text_serialization/ |
The JSON format described in that documentation does not exist yet, and is not the same as the JSON that arises from converting protobuf messages to JSON. |
We can skip the JSON part then. I understand you have further concerns about the |
| */ | ||
| public io.substrait.proto.Plan toProto() { | ||
| return new PlanProtoConverter().toProto(this); | ||
| } |
There was a problem hiding this comment.
Thinking on this some more, it's fine to include this.
I noticed that whenever we wanted to serialize a Plan to Proto one would have to instantiate a
PlanToProtoConverterand call thePlanToProtoConverter.toProto()instead I think we can offer some convenience by adding aPlan.toProto()method which generates the proto from the current plan.This PR also changes the existing code to use the new
Plan.toProto()method. In that context I'm also fixing an issue with the Spark example code using an older static version of Substrait instead of the most recent one.Similarly, generating the proto JSON representation is quite complicated since it requires people to first convert a
Planto proto and then set up a protobuf JsonFormat printer to generate the proto JSON String which also requires people to declare an additional dependency. Instead we can hide all of this complexity and simply have aPlan.toJsonString()method which generates the proto JSON for the current plan.