You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Matt Bateman <ma...@lycono.com> on 2016/02/24 02:54:32 UTC

Translate "$0" to real name

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

Re: Translate "$0" to real name

Posted by Julian Hyde <jh...@apache.org>.
Ted,

Thanks for chiming in.

And, I’m very excited to see another project using Calcite. Nice work.

May I include SQL-Gremlin in the list of adapters on http://calcite.apache.org/docs/adapter.html?

Would it make sense to convert SQL-Gremlin into a true adapter (i.e. provide an implementation of SchemaFactory so that you could include a Gremlin schema in a Calcite model file alongside other schemas)?


Julian



> On Feb 25, 2016, at 6:02 AM, Ted Wilmes <te...@wellaware.us> wrote:
> 
> 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 <jh...@apache.org>
> Sent: Wednesday, February 24, 2016 6:44 PM
> To: dev@calcite.apache.org
> 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 <ma...@lycono.com> 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


Re: Translate "$0" to real name

Posted by Ted Wilmes <te...@wellaware.us>.
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 <jh...@apache.org>
Sent: Wednesday, February 24, 2016 6:44 PM
To: dev@calcite.apache.org
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 <ma...@lycono.com> 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

Re: Translate "$0" to real name

Posted by Julian Hyde <jh...@apache.org>.
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 <ma...@lycono.com> 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