Hi, ZheHu

Thanks for your reply, makes sense to me.

Best,
Ron

Zhe Hu <iluff...@163.com> 于2025年2月8日周六 20:35写道:

> As far as I can tell, RelToSqlConverter is a suitable way to unparse a
> RelNode, which is also how our team applied it currently.
> For your question 1, the output SQL after rel2sql may not be exactly the
> same as your original query when using some optimized rules, however, more
> efficient (at least this is one of the goals). And I think you can find
> some useful information here: https://calcite.apache.org/docs/algebra.html.
> Since we can set dialect for rel2sql, there may also be a little semantic
> difference, which provides you an option to query different data sources.
> For your question 2, if a RelNode cannot be converted to SQL text, I think
> it’s possibly a bug.
>
>
> I hope those information can be helpful for you.
>
>
> Best
> ZheHu
>
>
>
>
> ---- Replied Message ----
> | From | Ron Liu<ron9....@gmail.com> |
> | Date | 02/8/2025 15:50 |
> | To | <dev@calcite.apache.org> |
> | Subject | [Discuss] Converting RelNode/RexNode to SQL Text |
> Hello, Dev!
>
> I am a contributor to Apache Flink. As you know, Flink SQL uses Apache
> Calcite as a framework for SQL parsing and optimization. For a SQL, Calcite
> will go through the transformation of SQL Text -> SqlNode -> RelNode. Now I
> have a requirement to reverse parse RelNode to SQL Text. By digging into
> the Calcite code, I found a tool RelToSqlConverter that can convert RelNode
> to SQL Text. Since Calcite may generate some unreadable intermediate
> variables during the process of converting SQL text to RelNode, I have the
> following concern when using RelToSqlConverter to reverse parse RelNode to
> SQL:
> 1. Can the SQL text parsed by RelToSqlConverter be equal to the original
> input SQL text?
> 2. Does RelToSqlConverter support parsing all RelNodes to SQL text?
>
> To summarize, my key question is whether using RelToSqlConverter to unparse
> a RelNode into SQL text is a production-ready solution? Since I don't know
> much about Calcite, I came to the community to ask for help.
>
> Other input: I found that the Coral[1] project is using RelToSqlConverter
> to unparsing RelNode into SQL text, which looks like a viable solution.
>
> 1. https://github.com/linkedin/coral
>
> Best,
> Ron
>

Reply via email to