You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Ian Bertolacci <ia...@workday.com.INVALID> on 2021/10/25 20:34:29 UTC

Is there a mechanism for constant folding in Calcite?

Howdy,
Does Calcite have any mechanism for applying constant folding to RexNodes in a query?

We’ve been wondering why expressions like `1 + 2` don’t get folded into the constant `3`.
We’re aware of RexSimplify, but it only does constant folding for Boolean expressions (i.e. logical and (some) comparison operations)
And even with RexSimplify, we find that it still does not perform some (what we would consider trivial) optimizations on SEARCH expressions.
For example `SEARCH(123:BIGINT, Sarg[123L:BIGINT]:BIGINT)` should get folded into `true`, but isn’t.
(But that’s a separate conversation).

So: is constant folding on all expressions something that already exists in Calcite?
If so, what should we be looking at to configure Calcite to apply constant folding?

Thanks!
-Ian J. Bertolacci

Re: Is there a mechanism for constant folding in Calcite?

Posted by Julian Hyde <jh...@gmail.com>.
Chunwei is correct.

If there are expressions that you would expect to constant-folded by that rule that aren’t, please log a bug.

> On Oct 25, 2021, at 7:10 PM, Chunwei Lei <ch...@gmail.com> wrote:
> 
> Hi, Ian.
> 
> ReduceExpressionsRule is always used to do constant folding.
> 
> 
> Best,
> Chunwei
> 
> 
> On Tue, Oct 26, 2021 at 4:34 AM Ian Bertolacci
> <ia...@workday.com.invalid> wrote:
> 
>> Howdy,
>> Does Calcite have any mechanism for applying constant folding to RexNodes
>> in a query?
>> 
>> We’ve been wondering why expressions like `1 + 2` don’t get folded into
>> the constant `3`.
>> We’re aware of RexSimplify, but it only does constant folding for Boolean
>> expressions (i.e. logical and (some) comparison operations)
>> And even with RexSimplify, we find that it still does not perform some
>> (what we would consider trivial) optimizations on SEARCH expressions.
>> For example `SEARCH(123:BIGINT, Sarg[123L:BIGINT]:BIGINT)` should get
>> folded into `true`, but isn’t.
>> (But that’s a separate conversation).
>> 
>> So: is constant folding on all expressions something that already exists
>> in Calcite?
>> If so, what should we be looking at to configure Calcite to apply constant
>> folding?
>> 
>> Thanks!
>> -Ian J. Bertolacci
>> 


Re: Is there a mechanism for constant folding in Calcite?

Posted by Chunwei Lei <ch...@gmail.com>.
Hi, Ian.

ReduceExpressionsRule is always used to do constant folding.


Best,
Chunwei


On Tue, Oct 26, 2021 at 4:34 AM Ian Bertolacci
<ia...@workday.com.invalid> wrote:

> Howdy,
> Does Calcite have any mechanism for applying constant folding to RexNodes
> in a query?
>
> We’ve been wondering why expressions like `1 + 2` don’t get folded into
> the constant `3`.
> We’re aware of RexSimplify, but it only does constant folding for Boolean
> expressions (i.e. logical and (some) comparison operations)
> And even with RexSimplify, we find that it still does not perform some
> (what we would consider trivial) optimizations on SEARCH expressions.
> For example `SEARCH(123:BIGINT, Sarg[123L:BIGINT]:BIGINT)` should get
> folded into `true`, but isn’t.
> (But that’s a separate conversation).
>
> So: is constant folding on all expressions something that already exists
> in Calcite?
> If so, what should we be looking at to configure Calcite to apply constant
> folding?
>
> Thanks!
> -Ian J. Bertolacci
>