I wouldn't recommend traversing parsed SQL statements, but rather move it into 
relational algebra - from there you can use RelVisitor to visit nodes, extract 
information and build RelNode "sub-queries" that you then put inside the 
unnamed list and then easily convert these "sub-queries" back to the SQL string 
using RelToSqlConverter.


Ivan Grgurina
Research Assistant (ZEMRIS)
________________________________
[cid:fe07c196-4e22-427c-931a-c220db8d713a]<https://www.linkedin.com/in/igrgurina/>
 [cid:edd72890-b6b1-467a-8b7f-26cbc399bba2] 
<https://www.fer.unizg.hr/ivan.grgurina>

________________________________
From: אייל טרבלסי <[email protected]>
Sent: Wednesday, July 10, 2019 11:22 AM
To: [email protected]
Subject: How to traverse parsed SQL statements‏

Hi,


Is there any tutorial teaching how to traverse parsed SQL statements (I
read
https://github.com/michaelmior/calcite-notebooks/blob/master/query-parsing.ipynb
which
is a great intro).

What I am trying to achieve is to create valid "sub-queries" from a single
query, by traversing the AST and saving the valid "sub-trees" and convert
them back to query by toString(), for example the following query "SELECT *
FROM foo WHERE country='USA' AND state='New York' " will return the
following sub-queries:
1.  "SELECT * FROM foo "
2.  "SELECT * FROM foo WHERE country='USA' "
3. "SELECT * FROM foo WHERE state='New York' "
4. "SELECT * FROM foo WHERE country='USA' AND state='New York' "

I would love any advice/resource that can help me implement these.

Thanks,
Eyal Trabelsi

Reply via email to