You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Yogendra Sharma <sy...@live.com> on 2022/02/05 10:39:27 UTC

List of tables & Columns

Hi Community,

I had to gather the list of all fully qualified table names and thier column names used(referenced) jn a SELECT query.

I simply parsed the query and wrote a visitor to visit the SqlNode recursively.

While its working (may be with few bugs here and there), i am wondering if Calcite would already be doing it somewhere ir if there is an easier way to achieve this?


Thanks
Y



Get Outlook for Android<https://aka.ms/ghei36>

Re: List of tables & Columns

Posted by Roman Kondakov <ko...@mail.ru.INVALID>.
Hi, Yogendra

there is an utility method RelOptUtil#findAllTables that looks for all 
tables in the rel tree. It doesn't collect column names, but you can 
adopt it for this purpose.

It seems to me that solution with visitor should also work fine.

--
Roman Kondakov


On 07.02.2022 12:45, Zhe Hu wrote:
> Hi, Sharma.
> As far as I can tell, Calcite doesn’t provide a simple way to get table names or column names for a query(or maybe I miss something).
> But you can take a look at SqlSelect、SqlOrderBy and SqlWith if you want to do such things. Based on my own experience, SqlVisitor seems the only way to get table/column names or alias by visiting the SqlNode, at least that’s how I extract tables/columns、distinguish SQL type or rewriting SQL in practice.
> Hope it’s helpful for you.
>
>
> Best,
> ZheHu
>
>
>
>
> On 02/5/2022 18:39,Yogendra Sharma<sy...@live.com> wrote:
> Hi Community,
>
> I had to gather the list of all fully qualified table names and thier column names used(referenced) jn a SELECT query.
>
> I simply parsed the query and wrote a visitor to visit the SqlNode recursively.
>
> While its working (may be with few bugs here and there), i am wondering if Calcite would already be doing it somewhere ir if there is an easier way to achieve this?
>
>
> Thanks
> Y
>
>
>
> Get Outlook for Android<https://aka.ms/ghei36>

Re: Re:List of tables & Columns

Posted by Yogendra Sharma <sy...@live.com>.
Thank you so much. I love the spirit of this community.

Just came to my mind - when Calcite validates the query against a schema, it must be validating if all the columns and tables are present in the schema. So it must be extracting these details; no?

May be something for me to dig into.

Thank you.
________________________________
From: Zhe Hu <il...@163.com>
Sent: Monday, February 7, 2022 8:15 AM
To: dev@calcite.apache.org <de...@calcite.apache.org>
Subject: Re:List of tables & Columns

Hi, Sharma.
As far as I can tell, Calcite doesn’t provide a simple way to get table names or column names for a query(or maybe I miss something).
But you can take a look at SqlSelect、SqlOrderBy and SqlWith if you want to do such things. Based on my own experience, SqlVisitor seems the only way to get table/column names or alias by visiting the SqlNode, at least that’s how I extract tables/columns、distinguish SQL type or rewriting SQL in practice.
Hope it’s helpful for you.


Best,
ZheHu




On 02/5/2022 18:39,Yogendra Sharma<sy...@live.com> wrote:
Hi Community,

I had to gather the list of all fully qualified table names and thier column names used(referenced) jn a SELECT query.

I simply parsed the query and wrote a visitor to visit the SqlNode recursively.

While its working (may be with few bugs here and there), i am wondering if Calcite would already be doing it somewhere ir if there is an easier way to achieve this?


Thanks
Y



Get Outlook for Android<https://aka.ms/ghei36>

Re:List of tables & Columns

Posted by Zhe Hu <il...@163.com>.
Hi, Sharma. 
As far as I can tell, Calcite doesn’t provide a simple way to get table names or column names for a query(or maybe I miss something).
But you can take a look at SqlSelect、SqlOrderBy and SqlWith if you want to do such things. Based on my own experience, SqlVisitor seems the only way to get table/column names or alias by visiting the SqlNode, at least that’s how I extract tables/columns、distinguish SQL type or rewriting SQL in practice.
Hope it’s helpful for you.


Best,
ZheHu




On 02/5/2022 18:39,Yogendra Sharma<sy...@live.com> wrote:
Hi Community,

I had to gather the list of all fully qualified table names and thier column names used(referenced) jn a SELECT query.

I simply parsed the query and wrote a visitor to visit the SqlNode recursively.

While its working (may be with few bugs here and there), i am wondering if Calcite would already be doing it somewhere ir if there is an easier way to achieve this?


Thanks
Y



Get Outlook for Android<https://aka.ms/ghei36>