My real goal is to know which virtual columns are used in query.

- I tried to use `getColumnOrigins`, here is one test in RelMetadataTest
```
@Test void testVirtualColumnOrigins() {
final String sql = "select E from VIRTUALCOLUMNS.VC_T1 "
+ "for system_time as of TIMESTAMP '2011-01-02 00:00:00'";
// Actual column name is A, but I need E.
sql(sql).withCatalogReaderFactory(MockCatalogReaderExtended::create)
.assertColumnOriginSingle("VC_T1", "E", false);
// I know that A is reasonable value because E = A + 1. (The root column
origin should be A.)
}
```

- Visit SqlNode is another solution, but there are some fields not be
trimmed.

I want to know if anyone has suggestions to get virtual column that query
used.

Thank you for your reply.

On Thu, 8 Sept 2022 at 14:55, Julian Hyde <[email protected]> wrote:

> You know, when people ask ‘Does Calcite support lineage?’, I’m never quite
> sure. People mean different things by lineage, and it takes a bit of effort
> to set up the required APIs.
>
> I think the way to solve this question is with unit tests.
>
> Can write a unit test that fails, or point to an existing test that almost
> does what you need? For example, is there a test to get the lineage of a
> view column?
>
> Julian
>
>
> > On Sep 5, 2022, at 2:52 AM, Jiajun Xie <[email protected]>
> wrote:
> >
> > Hi, all:
> > I want to know which virtual column is in use. For example,
> > ```
> > CREATE TABLE peoples(age int, virtual_age int as (age + 1) virtual);
> > SELECT virtual_age from peoples;
> > ```
> > After converting, the virtual column is expanded to expression.
> > ```
> > LogicalProject(virtual_age=[+($0, 1)])
> >  LogicalTableScan(table=[[default_ns, default, peoples]])
> > ```
> > So `RelMetadataQuery#getColumnOrigins` return RelColumnOrigin that is
> > age(not is virtual_age).
> >
> > I try to rewrite code in the implementation class of
> > `InitializerExpressionFactory`, but I can't know which column is in use.
> > When I confirm which column is in use, I can't know if the expression is
> > from a virtual column.
> >
> > Does anyone have relevant experience?  Thanks~
>
>

Reply via email to