Hi Lana, As Stamatis said, we use a custom RelWriter and the explain method on the rel nodes to dump the plan to JSON. It is the same few lines as here, but we've plucked them out of RelOptUtil into our own serializer class: https://github.com/apache/calcite/blob/7f5e9b8b7e6b4afd8e4f21524aa3c4ce8b7ddb61/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java#L2132
All our code using Calcite is open source, and the serialization code is available in our open source repo if you want to have a loook: https://github.com/omnisci/omniscidb/blob/master/java/calcite/src/main/java/org/apache/calcite/rel/externalize/MapDRelJson.java If there is a more canonical way of doing this, I would be interested in hearing about it. We also recently wanted to dump SQL nodes (DML commands) to JSON, but didn't see a similar interface at the SQL level so we cobbled together our own override of toString. Alex On Sun, Jun 6, 2021 at 3:52 PM Stamatis Zampetakis <[email protected]> wrote: > > Hi Lana, > > I think what you are looking for is RelOptUtil#dumpPlan [1] > using SqlExplainFormat.JSON as one of the parameters. > You can check the callers of this method for examples on how to use it. > > Best, > Stamatis > > [1] > https://github.com/apache/calcite/blob/7f5e9b8b7e6b4afd8e4f21524aa3c4ce8b7ddb61/core/src/main/java/org/apache/calcite/plan/RelOptUtil.java#L2116 > > On Sun, Jun 6, 2021 at 10:42 PM Lana Ramjit <[email protected]> wrote: > > > Hi all, > > > > I was reading this old blog post from OmniSci > > < > > https://www.omnisci.com/blog/fast-and-flexible-query-analysis-at-mapd-with-apache-calcite-2 > > >and > > they mention that to use Calcite-generated plans in their C++ library, they > > serialized the relational algebra output by Calcite into JSON. I'd like to > > do something like this for a project but I can't seem to find any good > > documentation of this. I found this page in the docs > > <https://calcite.apache.org/docs/model.html> about the model, but what I > > am > > looking for hopefully is a function that I can pass the root of a Calcite > > plan and get a JSONified serialization. Does this exist? > > > > Thanks, > > Lana > >
