You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by "Peer Arimond, INF-I" <ar...@hochschule-trier.de> on 2019/09/20 12:39:35 UTC

Looking for guides on SQL Parser

Hello Apache Calcite,

I´m currently working on a project, wich connects diffrent database systems, relational such as nosql. Part of the project is to translate an SQL query into our own model of relational algebra. After making some research i saw Apache Calcite and especially the SQL Parser of Apache Calcite and i think it could help me a lot.
Is there only the documentation or are there may be more guides or something to get deeper into the SQL Parser?
I want to parse a query and walk recursively over each node from the query tree and for example print every Node and it´s function.
If i could achieve that it would be a good beginning. May be you can help?

Greetings,

Peer Arimond

--
http://webmail.fh-trier.de


Re: Looking for guides on SQL Parser

Posted by Muhammad Gelbana <m....@gmail.com>.
The parser is based on JavaCC[1] so you can download it and explore its
"examples" folder for tutorials to understand how it works.

If that's not what you're looking for, then you might debug through the
generated core parser[2] (There is also what we call Babel parser,
developed to parse all sorts of syntaxes other than the standard supported
by the core parser).

You can also enable the parser's debugging mode [3] which can be specified
in the grammer file or through the command line [4].

If that's not what you're looking for either then you're probably looking
for "visiting" the parsed tree to traverse all its contents ? You can do
that by providing an "SqlVisitor" to the SQL tree root node (ie.
SqlNode.accept(SqlVisitor visitor)).

[1] https://javacc.org/getting-started
[2] org.apache.calcite.sql.parser.impl.SqlParserImpl
[3] https://javacc.org/javaccgrm#prod6
[4] https://javacc.org/commandline

Thanks,
Gelbana


On Sat, Sep 21, 2019 at 10:31 PM Peer Arimond, INF-I <
arimondp@hochschule-trier.de> wrote:

> Hello Apache Calcite,
>
> I´m currently working on a project, wich connects diffrent database
> systems, relational such as nosql. Part of the project is to translate an
> SQL query into our own model of relational algebra. After making some
> research i saw Apache Calcite and especially the SQL Parser of Apache
> Calcite and i think it could help me a lot.
> Is there only the documentation or are there may be more guides or
> something to get deeper into the SQL Parser?
> I want to parse a query and walk recursively over each node from the query
> tree and for example print every Node and it´s function.
> If i could achieve that it would be a good beginning. May be you can help?
>
> Greetings,
>
> Peer Arimond
>
> --
> http://webmail.fh-trier.de
>
>

Re: Looking for guides on SQL Parser

Posted by Danny Chan <yu...@gmail.com>.
Hey, Peer Arimond ~

The server module is really a good start for extending the parser, you can take a reference if you want to have custom syntax.

I don’t get what you mean by “print the sql node”, but if you want to unparse the SqlNode to original sql string, invoke the SqlNode#toString is okey.

Best,
Danny Chan
在 2019年9月22日 +0800 AM4:31,Peer Arimond, INF-I <ar...@hochschule-trier.de>,写道:
> Hello Apache Calcite,
>
> I´m currently working on a project, wich connects diffrent database systems, relational such as nosql. Part of the project is to translate an SQL query into our own model of relational algebra. After making some research i saw Apache Calcite and especially the SQL Parser of Apache Calcite and i think it could help me a lot.
> Is there only the documentation or are there may be more guides or something to get deeper into the SQL Parser?
> I want to parse a query and walk recursively over each node from the query tree and for example print every Node and it´s function.
> If i could achieve that it would be a good beginning. May be you can help?
>
> Greetings,
>
> Peer Arimond
>
> --
> http://webmail.fh-trier.de
>