Not sure if this would be of any help, but I worked through a similar sort of 
thing in this class:

https://github.com/twilmes/sql-gremlin/blob/cef926c71645165b4c469ebc05e23df0c3591747/src/main/java/org/twilmes/sql/gremlin/processor/FieldMapVisitor.java


I'm using Calcite as part of a project that converts SQL to the Gremlin graph 
query language.  Because of how the Gremlin queries are constructed, I needed 
to be able to trace the provenance of the columns at each level back to their 
original column name.  This particular code is executed during a depth first 
traversal of the RelNodes.

--Ted

________________________________________
From: Julian Hyde <[email protected]>
Sent: Wednesday, February 24, 2016 6:44 PM
To: [email protected]
Subject: Re: Translate "$0" to real name

Scalar expressions (RexNode) are, by design, separate from relational 
expressions (RelNode). Therefore a reference to an input field (RexInputRef) 
contains the ordinal and type of the field that it references but not its name 
or any other information.

It’s useful that RexNodes are self-contained; they are easier to canonize, and 
there are fewer concerns about them being the source of memory leaks.

If you want to print extra information about a RexNode you need to supply the 
list of RelNodes that are the context. When used in a Filter or Project, that 
list is just [input]. When used in a Join, that list is [left, right].

It would be nice if, say, the explain of Filter, Project and Join used the 
input field names rather than $n. If you wrote this we could hook it up.

Lastly, note that the names of the fields of RelNodes may not be the “real 
names” you are hoping for. We try to preserve the names from SQL, but there are 
times when they get lost, especially after applying transformation rules. All 
we can really guarantee is that the names are unique within each input.

Julian


> On Feb 23, 2016, at 5:54 PM, Matt Bateman <[email protected]> wrote:
>
> Hi All,
>
> I'm sure this is something simple I'm missing. When evaluating a where
> clause the RexInputRef uses the "$index" notation. How do I get from there
> to the actual name of the column? The javadoc for RexInputRef talks about
> this but doesn't indicate how to do the actual translation.
>
> Thanks,
>
> Matt

Reply via email to