Hello, mbudiu:
Based on my experience, constant folding can occur in two stages.
- Enable it by `RelBuilder$Config$withSimplify`[1] in the convert stage
- Add `RelOptRules$CONSTANT_REDUCTION_RULES`[2] in the optimize stage
If your RexNode is not complex, you can directly use RexSimplify. For
example
```[3]
final RexSimplify simplify =
new RexSimplify(rexBuilder, RelOptPredicateList.EMPTY,
RexUtil.EXECUTOR)
.withParanoid(true);
return simplify.simplifyUnknownAs(e, RexUnknownAs.UNKNOWN);
```
[1]
https://github.com/apache/calcite/blob/8ea4160f10e95aca6c3b0029d505bbc56975a873/core/src/main/java/org/apache/calcite/tools/RelBuilder.java#L4841
[2]
https://github.com/apache/calcite/blob/8ea4160f10e95aca6c3b0029d505bbc56975a873/core/src/main/java/org/apache/calcite/plan/RelOptRules.java#L132
[3]
https://github.com/apache/calcite/blob/8ea4160f10e95aca6c3b0029d505bbc56975a873/core/src/test/java/org/apache/calcite/rex/RexProgramTestBase.java#L187
On Sat, 3 Jun 2023 at 04:33, <[email protected]> wrote:
> Hello,
>
>
>
> I was looking for rules that apply algebraic optimizations to RexNode
> expressions, such as 0 + x = x, but I couldn't find any.
>
> Is there such a rule?
>
>
>
> Mihai
>
>