You can customize a RelVisitor to visit the RelNode, and collect the
columns from TableScan's rowtype.

王驰 <wang...@kuaishou.com> 于2020年4月16日周四 下午11:23写道:

> Hi folks,
>
>
> We're using CalCite in our project for SQL parsing and validating. We have
> a question: is there any way to get all used columns from a SQL?
>
>
> Consider the following case:
>
> we have two tables `user` and `user_region`. And the SQL is like
>
>
> ```
>
> SELECT
>
>     id, name, age, country, province, city
>
> FROM
>
>     user
>
>     INNER JOIN user_region ON user.id = user_region.user_id
>
> WHERE age > 18;
>
> ```
>
>
> The result will be a Map with two keys:
>
>
>    - 'user' --> List('id', 'name', 'age')
>    - 'user_region' --> List('country', 'province', 'city', 'user_id')
>
>
> ======
>
> I've tried with SqlValidator (along with SqlValidatorScope,
> SqlValidatorNamespace) but found no easy ways to do this.
> I also tried to replay the validate process in our code but it seems
> impossible since most classes used are package private.
>
>
> Could you please give us some suggestions? Thanks!
>
>

Reply via email to