I have seen the constant folding rules you mention in [2], but these seen to require all operands to be compile-time known. Algebraic optimization rules can work even when only some of the operands are constant, such as addition of an arbitrary expression with zero.
I will take a look at the simplification code to see whether it handles such cases. Thank you, Mihai -----Original Message----- From: Jiajun Xie Sent: Friday, June 02, 2023 7:08 PM To: dev@calcite.apache.org Subject: Re: Algebraic optimizations rule 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, <mbu...@gmail.com> 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 > >