You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by GitBox <gi...@apache.org> on 2020/12/10 08:14:21 UTC

[GitHub] [calcite] rubenada commented on a change in pull request #2253: [CALCITE-4385] Extracts and eliminates/merges the condition that has common expressions (Jiatao Tao)

rubenada commented on a change in pull request #2253:
URL: https://github.com/apache/calcite/pull/2253#discussion_r539960286



##########
File path: core/src/main/java/org/apache/calcite/rex/RexSimplify.java
##########
@@ -1698,6 +1699,115 @@ RexNode simplifyAnd2ForUnknownAsFalse(List<RexNode> terms,
     }
   }
 
+  /**
+   * <p>Simplifies AND/OR condition that has common expressions,
+   * extracts and eliminates/merges them as much as possible.</p>
+   * <ul>
+   * <li>(a OR b) AND (a OR b OR c OR d) =&gt; (a OR b)
+   * <li>(a OR b OR c OR d) AND (a OR b OR e OR f) =&gt; (a OR b) OR ((c OR d) AND (e OR f))
+
+   * <li>(a AND b) OR (a AND b AND c) =&gt; (a AND b)
+   * <li>(a AND b AND c AND d) OR (a AND b AND e AND f) =&gt;
+   * (a AND b) AND ((c AND d) OR (e AND f))
+   * </ul>
+   * <p> The difference between {@link #simplifyAnd} is that {@link #simplifyAnd} mainly
+   * simplifies expressions whose answer can be determined without evaluating both sides,
+   * like: FALSE AND (xxx) =&gt; FALSE</p>
+   */
+  public RexNode eliminateCommonExprInCondition(RexNode node) {
+    if (!(node instanceof RexCall)

Review comment:
       I think the first part of the condition is redundant.
   `if (node.getKind() != SqlKind.AND && node.getKind() != SqlKind.OR)` should be enough




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org