You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Marc Prud'hommeaux <ma...@glimpse.io> on 2017/10/06 19:33:11 UTC

RelBuilder inputCount for field reference

Using the RelBuilder API, I’d like to get a field by alias & name without having to keep track of the inputCount. I’ve found that the following always seems to work fine (after making stack a public variable):

  builder.field(builder.stack.count(), “MYALIAS”, “myfield”)

My question: why does RelBuilder.field(String, String) use an inputCount of 1 instead of the size of the stack? Doing so would allow people to search for field names without having to keep track of the number of inputs.

I understand why accessing fields by index require the inputCount and inputOrdinal, but searching for fields by name could just scan the entire stack and return the first matching field name + alias.



Re: RelBuilder inputCount for field reference

Posted by Julian Hyde <jh...@apache.org>.
I like it.

I suppose that RelBuilder.join would continue to return RelBuilder, but “on” would be allowed only if the previous call was to “join”.

A “using” method should probably be added for completeness.

And the field(int, int) and field(int, String) methods can be deprecated.

Can you log a JIRA case please.

Julian


> On Oct 11, 2017, at 7:17 AM, Marc Prud'hommeaux <ma...@glimpse.io> wrote:
> 
> Julian-
> 
> Is the only scenario in which the stack depth needs to be specified when you are preforming a join? If so, perhaps the RelBuildr API could be simplified so that rather than having to do:
> 
> 	builder.scan("EMP").as("e").scan("DEPT").join(JoinRelType.LEFT, builder.equals(builder.field(2, "e", "DEPTNO"), builder.field(2, "DEPT", "DEPTNO")))
> 
> One could instead specify an “on” condition for the join after the join has been made (and thus after the stack has been flattened):
> 
> 	builder.scan("EMP").as("e").scan("DEPT").join(JoinRelType.LEFT).on(builder.equals(builder.field("e", "DEPTNO"), builder.field("DEPT", "DEPTNO")))
> 
> This would be similar to the filter example from RelBuilderTest.testAliasPastTop():
> 
> 	builder.scan("EMP").as("e").scan("DEPT").join(JoinRelType.LEFT).filter(builder.equals(builder.field("e", "DEPTNO"), builder.field("DEPT", "DEPTNO")))
> 
> 	-Marc
> 
> 
>> On Oct 6, 2017, at 4:39 PM, Julian Hyde <jh...@apache.org> wrote:
>> 
>> When forming a reference it needs to know how many inputs you are
>> going to pop off the stack in your next operation. Most operations pop
>> 1, but join pops 2. Set operations may pop more, but they don't use
>> expressions, so it's moot.
>> 
>> You don't necessarily pop the whole stack. For instance, if you're
>> forming a right-deep join (a join (b join c)) for instance. You would
>> have a, b, c on the stack and just pop (b, c) to make the first join.
>> 
>> So, I can't see a way to remove the inputCount parameter.
>> 
>> On Fri, Oct 6, 2017 at 12:33 PM, Marc Prud'hommeaux <ma...@glimpse.io> wrote:
>>> 
>>> Using the RelBuilder API, I’d like to get a field by alias & name without having to keep track of the inputCount. I’ve found that the following always seems to work fine (after making stack a public variable):
>>> 
>>> builder.field(builder.stack.count(), “MYALIAS”, “myfield”)
>>> 
>>> My question: why does RelBuilder.field(String, String) use an inputCount of 1 instead of the size of the stack? Doing so would allow people to search for field names without having to keep track of the number of inputs.
>>> 
>>> I understand why accessing fields by index require the inputCount and inputOrdinal, but searching for fields by name could just scan the entire stack and return the first matching field name + alias.
>>> 
>>> 
> 


Re: RelBuilder inputCount for field reference

Posted by Marc Prud'hommeaux <ma...@glimpse.io>.
Julian-

Is the only scenario in which the stack depth needs to be specified when you are preforming a join? If so, perhaps the RelBuildr API could be simplified so that rather than having to do:

	builder.scan("EMP").as("e").scan("DEPT").join(JoinRelType.LEFT, builder.equals(builder.field(2, "e", "DEPTNO"), builder.field(2, "DEPT", "DEPTNO")))

One could instead specify an “on” condition for the join after the join has been made (and thus after the stack has been flattened):

	builder.scan("EMP").as("e").scan("DEPT").join(JoinRelType.LEFT).on(builder.equals(builder.field("e", "DEPTNO"), builder.field("DEPT", "DEPTNO")))

This would be similar to the filter example from RelBuilderTest.testAliasPastTop():

	builder.scan("EMP").as("e").scan("DEPT").join(JoinRelType.LEFT).filter(builder.equals(builder.field("e", "DEPTNO"), builder.field("DEPT", "DEPTNO")))

	-Marc


> On Oct 6, 2017, at 4:39 PM, Julian Hyde <jh...@apache.org> wrote:
> 
> When forming a reference it needs to know how many inputs you are
> going to pop off the stack in your next operation. Most operations pop
> 1, but join pops 2. Set operations may pop more, but they don't use
> expressions, so it's moot.
> 
> You don't necessarily pop the whole stack. For instance, if you're
> forming a right-deep join (a join (b join c)) for instance. You would
> have a, b, c on the stack and just pop (b, c) to make the first join.
> 
> So, I can't see a way to remove the inputCount parameter.
> 
> On Fri, Oct 6, 2017 at 12:33 PM, Marc Prud'hommeaux <ma...@glimpse.io> wrote:
>> 
>> Using the RelBuilder API, I’d like to get a field by alias & name without having to keep track of the inputCount. I’ve found that the following always seems to work fine (after making stack a public variable):
>> 
>>  builder.field(builder.stack.count(), “MYALIAS”, “myfield”)
>> 
>> My question: why does RelBuilder.field(String, String) use an inputCount of 1 instead of the size of the stack? Doing so would allow people to search for field names without having to keep track of the number of inputs.
>> 
>> I understand why accessing fields by index require the inputCount and inputOrdinal, but searching for fields by name could just scan the entire stack and return the first matching field name + alias.
>> 
>> 


Re: RelBuilder inputCount for field reference

Posted by Julian Hyde <jh...@apache.org>.
When forming a reference it needs to know how many inputs you are
going to pop off the stack in your next operation. Most operations pop
1, but join pops 2. Set operations may pop more, but they don't use
expressions, so it's moot.

You don't necessarily pop the whole stack. For instance, if you're
forming a right-deep join (a join (b join c)) for instance. You would
have a, b, c on the stack and just pop (b, c) to make the first join.

So, I can't see a way to remove the inputCount parameter.

On Fri, Oct 6, 2017 at 12:33 PM, Marc Prud'hommeaux <ma...@glimpse.io> wrote:
>
> Using the RelBuilder API, I’d like to get a field by alias & name without having to keep track of the inputCount. I’ve found that the following always seems to work fine (after making stack a public variable):
>
>   builder.field(builder.stack.count(), “MYALIAS”, “myfield”)
>
> My question: why does RelBuilder.field(String, String) use an inputCount of 1 instead of the size of the stack? Doing so would allow people to search for field names without having to keep track of the number of inputs.
>
> I understand why accessing fields by index require the inputCount and inputOrdinal, but searching for fields by name could just scan the entire stack and return the first matching field name + alias.
>
>