I have not looked at the code, so excuse me if this is a terrible question,
but is this recursive?
Ie:
create view a_view as select a_column from a_table where b_column = 1;
select * from
( -- this could be a view or just a dependent subquery like this
select cast(sq1_col ...) as a_column from (
-- same here, but it is explicitly a view
select cast(a_column ...) as sq1_col from a_view
) sq2
) sq1
The metadata for a_column might be completely different in each of the
views until you get to a_view. I added a casts here to make that clear.
On Tue, Nov 9, 2021 at 5:35 AM JiaTao Tao <[email protected]> wrote:
> May be you can try this:
> org.apache.calcite.rel.metadata.RelMetadataQuery#getColumnOrigins
> But i'm not tested yet.
> Pls give feedback whether it works or not.
>
> Regards!
>
> Aron Tao
>
>
> Armstrong <[email protected]> 于2021年11月3日周三 下午10:09写道:
>
> > Hi guys,
> > Thanks for your time to read this help message. I'm new to Calcite
> and
> > reading some codes and examples from calcite Github repo. I'm wandering
> how
> > to get the column real name and type from view.
> > For example, I have some SQL as below. A kafka topic table left
> join
> > MySQL table, and use a View join_result_view represent the join result. I
> > want to get the real column name and data type from this view.
> > How to get result like this ? "user_id", bigint ; "log_time",
> bigint
> > I already try use SqlParse parse these sqls, and get the SqlNode,
> but
> > I can't get the real column name and type. Maybe I missed out the correct
> > method. Hopefully some one can identify the problem, thanks a lot.
> >
> > CREATE TABLE user_action_source (
> > `user_id` STRING,
> > `item_id` BIGINT,
> > `bhv_type` STRING,
> > `bhv_time` INT,
> > `play_duration` INT,
> > `ts` BIGINT,
> > proc_time as PROCTIME()
> > ) WITH (
> > 'connector' = 'kafka',
> > 'topic' = 'user_action_log',
> > 'parallelism' = '5',
> > 'properties.cluster' = 'asv_cluster',
> > 'properties.group.id' = 'demo-job',
> > 'scan.startup.mode' = 'latest-offset',
> > 'format' = 'json',
> > 'json.fail-on-missing-field' = 'false',
> > 'json.ignore-parse-errors' = 'true',
> > 'scan.manually-commit-offsets-interval' = '5000'
> > );
> >
> > CREATE TABLE item_source (
> > `item_id` BIGINT,
> > `video_name` STRING,
> > `video_count` INT,
> > `video_duration` INT,
> > `authors` STRING
> > ) WITH (
> > 'connector' = 'jdbc',
> > 'url' = 'jdbc:mysql://localhost:3306/mydatabase',
> > 'table-name' = 'item_info'
> > );
> >
> > create view join_result_view as
> > select a.user_id, a.item_id, a.bhv_type, a.ts as log_time, b.video_name,
> > b.video_count, b.video_duration, b.authors
> > from user_action_source as a left join item_source FOR SYSTEM_TIME AS
> OF
> > a.proc_time as b
> > on a.item_id = b.item_id;
> >
>