You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Gaurav Sehgal <ga...@gmail.com> on 2020/06/04 01:41:41 UTC
Columns used in query
Hi,
I've a use case where i want to find all the columns, and their respective
tables accessed in a sql query. I'm able to find all the table names by
converting the sql query to RelNode and then visiting the TableScan node
but not sure what would be the right approach to find all the column names.
Can someone help me with this?
Thanks
Gaurav Sehgal
Re: Columns used in query
Posted by Haisheng Yuan <hy...@apache.org>.
Hmm, the getColumnOrigins only gives you output columns, not the used columns.
You can follow the example of ColumnOrigins, but for the Join operator, should also process the join conditions.
For Filter operator, need to process the filter condition.
On 2020/06/04 10:24:55, Gaurav Sehgal <ga...@gmail.com> wrote:
> Hi Haisheng,
>
> Thanks for replying so quickly.
>
> I'm able to find all the columns used in Project expression
> using RelMetadataQuery.getColumnOrigins, but not sure how to go about other
> expressions like join, and filter.
>
> Example:
>
> with t as (select test.colb from test left join test2 on test2.colb =
> 34) select case colb when 1 then 'one' else 'many' end from t union
> all select test.cola from test
>
> RelMetadataQuery.getColumnOrigins is returning columns test.cola and
> test.colb, but not test2.colb which is used in join expression.
>
> On Thu, 4 Jun, 2020, 7:22 AM Haisheng Yuan, <hy...@apache.org> wrote:
>
> > Hi Gaurav,
> >
> > You may find this useful:
> >
> > https://lists.apache.org/thread.html/rc38d12de860f64e8e2926b7bcf6f2e9e6bcbfbc7ca5e886a71323b47%40%3Cdev.calcite.apache.org%3E
> >
> > On 2020/06/04 01:41:41, Gaurav Sehgal <ga...@gmail.com>
> > wrote:
> > > Hi,
> > >
> > > I've a use case where i want to find all the columns, and their
> > respective
> > > tables accessed in a sql query. I'm able to find all the table names by
> > > converting the sql query to RelNode and then visiting the TableScan node
> > > but not sure what would be the right approach to find all the column
> > names.
> > >
> > > Can someone help me with this?
> > >
> > >
> > > Thanks
> > > Gaurav Sehgal
> > >
> >
>
Re: Columns used in query
Posted by Gaurav Sehgal <ga...@gmail.com>.
Hi Haisheng,
Thanks for replying so quickly.
I'm able to find all the columns used in Project expression
using RelMetadataQuery.getColumnOrigins, but not sure how to go about other
expressions like join, and filter.
Example:
with t as (select test.colb from test left join test2 on test2.colb =
34) select case colb when 1 then 'one' else 'many' end from t union
all select test.cola from test
RelMetadataQuery.getColumnOrigins is returning columns test.cola and
test.colb, but not test2.colb which is used in join expression.
On Thu, 4 Jun, 2020, 7:22 AM Haisheng Yuan, <hy...@apache.org> wrote:
> Hi Gaurav,
>
> You may find this useful:
>
> https://lists.apache.org/thread.html/rc38d12de860f64e8e2926b7bcf6f2e9e6bcbfbc7ca5e886a71323b47%40%3Cdev.calcite.apache.org%3E
>
> On 2020/06/04 01:41:41, Gaurav Sehgal <ga...@gmail.com>
> wrote:
> > Hi,
> >
> > I've a use case where i want to find all the columns, and their
> respective
> > tables accessed in a sql query. I'm able to find all the table names by
> > converting the sql query to RelNode and then visiting the TableScan node
> > but not sure what would be the right approach to find all the column
> names.
> >
> > Can someone help me with this?
> >
> >
> > Thanks
> > Gaurav Sehgal
> >
>
Re: Columns used in query
Posted by Haisheng Yuan <hy...@apache.org>.
Hi Gaurav,
You may find this useful:
https://lists.apache.org/thread.html/rc38d12de860f64e8e2926b7bcf6f2e9e6bcbfbc7ca5e886a71323b47%40%3Cdev.calcite.apache.org%3E
On 2020/06/04 01:41:41, Gaurav Sehgal <ga...@gmail.com> wrote:
> Hi,
>
> I've a use case where i want to find all the columns, and their respective
> tables accessed in a sql query. I'm able to find all the table names by
> converting the sql query to RelNode and then visiting the TableScan node
> but not sure what would be the right approach to find all the column names.
>
> Can someone help me with this?
>
>
> Thanks
> Gaurav Sehgal
>