I'm not a Calcite expert but I've recently worked on a project involving
parsing and reconstructing SQL with Calcite.
You may want to have a look at the toSqlString
<https://calcite.apache.org/javadocAggregate/org/apache/calcite/sql/SqlNode.html#toSqlString(org.apache.calcite.sql.SqlDialect,boolean)>
method of SqlNode. It generates the SQL statements from the node.
Generation is based on a SQL Dialect, and a lot of Dialects are available
<https://github.com/apache/calcite/tree/master/core/src/main/java/org/apache/calcite/sql/dialect>.
You can build your custom dialect if need be.

Parsing SQL: SqlNode myNode = SqlParser.create(myQuery, mySqlParserConfig);
GeneratingSQL: myNode.toSqlString(myDialect)

Cheers
Cyril de Catheu

On Wed, Nov 24, 2021 at 11:38 AM Sandeep Nayak <[email protected]>
wrote:

> Hello,
>
> I have been looking for a library which will allow me to use an object tree
> to generate a SQL. Calcite came up in my search but after taking a look at
> the codebase my conclusion is that Calcite provides the ability to parse
> SQL statements into an object tree represented as SQLNode (and derived
> classes) instances which subsequently can be used to perform optimizations
> by generating  relational algebra for the logical query.
>
> Calcite however does not provide classes which can be used to assemble a
> tree and generate SQL statements. From the contracts at least SQLNode takes
> in a Parser position and there are no other contracts which indicate such
> an option. Can someone confirm if this is inaccurate?
>
> If not Calcite, are there other open source libraries out there which allow
> this?
>
> Thanks in advance.
>
> -Sandeep
>

Reply via email to