From ea2984fb181dcb18d91e5ad4b6ad374ecc1eac00 Mon Sep 17 00:00:00 2001 From: Ruben Quesada Lopez Date: Wed, 23 Sep 2026 15:54:31 +0100 Subject: [PATCH] [CALCITE-739] Extend RexUtil.pullFactors to recognize additional common factors (follow-up) --- core/src/main/java/org/apache/calcite/rex/RexUtil.java | 4 ++-- .../test/java/org/apache/calcite/rex/RexProgramTest.java | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/apache/calcite/rex/RexUtil.java b/core/src/main/java/org/apache/calcite/rex/RexUtil.java index 1c11b0e75050..13f89bad9269 100644 --- a/core/src/main/java/org/apache/calcite/rex/RexUtil.java +++ b/core/src/main/java/org/apache/calcite/rex/RexUtil.java @@ -2967,7 +2967,7 @@ private RexNode pull(RexNode rex) { } return and(Iterables.concat(factors.values(), ImmutableList.of(or(list)))); default: - return normalizeComparison(rex); + return rex; } } @@ -2994,7 +2994,7 @@ private LinkedHashMap commonFactors(List nodes) { if (i++ == 0) { for (RexNode conjunction : RelOptUtil.conjunctions(node)) { RexNode normalized = normalizeComparison(conjunction); - map.put(normalized, normalized); + map.put(normalized, conjunction); } } else { map.keySet().retainAll( diff --git a/core/src/test/java/org/apache/calcite/rex/RexProgramTest.java b/core/src/test/java/org/apache/calcite/rex/RexProgramTest.java index db668434734e..dc3c5fb42321 100644 --- a/core/src/test/java/org/apache/calcite/rex/RexProgramTest.java +++ b/core/src/test/java/org/apache/calcite/rex/RexProgramTest.java @@ -896,13 +896,13 @@ private void checkExponentialCnf(int n) { final RexNode bool0 = rexBuilder.makeInputRef(booleanType, 0); final RexNode bool1 = rexBuilder.makeInputRef(booleanType, 1); final RexNode seven = literal(7); - checkPullFactors(eq(ref6, ref3), "=($3, $6)"); - checkPullFactors(gt(ref6, ref3), "<($3, $6)"); - checkPullFactors(le(seven, ref3), ">=($3, 7)"); + checkPullFactors(eq(ref6, ref3), "=($6, $3)"); + checkPullFactors(gt(ref6, ref3), ">($6, $3)"); + checkPullFactors(le(seven, ref3), "<=(7, $3)"); checkPullFactors( or(and(eq(ref6, ref3), bool0), and(eq(ref3, ref6), bool1)), - "AND(=($3, $6), OR($0, $1))"); + "AND(=($6, $3), OR($0, $1))"); } @Test void testSimplify() {