Class RexSimplify

java.lang.Object
org.apache.calcite.rex.RexSimplify

public class RexSimplify extends Object
Context required to simplify a row-expression.
  • Field Details

  • Constructor Details

  • Method Details

    • withUnknownAsFalse

      @Deprecated public RexSimplify withUnknownAsFalse(boolean unknownAsFalse)
      Deprecated.
      Use methods with a RexUnknownAs argument, such as simplify(RexNode, RexUnknownAs).
      Returns a RexSimplify the same as this but with a specified defaultUnknownAs value.
    • withPredicates

      public RexSimplify withPredicates(RelOptPredicateList predicates)
      Returns a RexSimplify the same as this but with a specified predicates value.
    • withParanoid

      public RexSimplify withParanoid(boolean paranoid)
      Returns a RexSimplify the same as this but which verifies that the expression before and after simplification are equivalent.
      See Also:
      • verify(org.apache.calcite.rex.RexNode, org.apache.calcite.rex.RexNode, org.apache.calcite.rex.RexUnknownAs)
    • simplifyPreservingType

      public RexNode simplifyPreservingType(RexNode e)
      Simplifies a boolean expression, always preserving its type and its nullability.

      This is useful if you are simplifying expressions in a Project.

    • simplifyPreservingType

      public RexNode simplifyPreservingType(RexNode e, RexUnknownAs unknownAs, boolean matchNullability)
    • simplify

      public RexNode simplify(RexNode e)
      Simplifies a boolean expression.

      In particular:

      • simplify(x = 1 OR NOT x = 1 OR x IS NULL) returns TRUE
      • simplify(x = 1 AND FALSE) returns FALSE

      Handles UNKNOWN values using the policy specified when you created this RexSimplify. Unless you used a deprecated constructor, that policy is RexUnknownAs.UNKNOWN.

      If the expression is a predicate in a WHERE clause, consider instead using simplifyUnknownAsFalse(RexNode).

      Parameters:
      e - Expression to simplify
    • simplifyUnknownAsFalse

      public final RexNode simplifyUnknownAsFalse(RexNode e)
      As simplify(RexNode), but for a boolean expression for which a result of UNKNOWN will be treated as FALSE.

      Use this form for expressions on a WHERE, ON, HAVING or FILTER(WHERE) clause.

      This may allow certain additional simplifications. A result of UNKNOWN may yield FALSE, however it may still yield UNKNOWN. (If the simplified expression has type BOOLEAN NOT NULL, then of course it can only return FALSE.)

    • simplifyUnknownAs

      public RexNode simplifyUnknownAs(RexNode e, RexUnknownAs unknownAs)
      As simplify(RexNode), but specifying how UNKNOWN values are to be treated.

      If UNKNOWN is treated as FALSE, this may allow certain additional simplifications. A result of UNKNOWN may yield FALSE, however it may still yield UNKNOWN. (If the simplified expression has type BOOLEAN NOT NULL, then of course it can only return FALSE.)

    • simplifyAnds

      @Deprecated public RexNode simplifyAnds(Iterable<? extends RexNode> nodes)
      Deprecated.
      Simplifies a conjunction of boolean expressions.
    • simplifyAnd

      @Deprecated public RexNode simplifyAnd(RexCall e)
      Deprecated.
    • simplifyOr

      @Deprecated public RexNode simplifyOr(RexCall call)
      Deprecated.
      Simplifies OR(x, x) into x, and similar. The simplified expression returns UNKNOWN values as is (not as FALSE).
    • simplifyOrs

      @Deprecated public RexNode simplifyOrs(List<RexNode> terms)
      Deprecated.
      Simplifies a list of terms and combines them into an OR. Modifies the list in place. The simplified expression returns UNKNOWN values as is (not as FALSE).
    • removeNullabilityCast

      public RexNode removeNullabilityCast(RexNode e)
      Removes any casts that change nullability but not type.

      For example, CAST(1 = 0 AS BOOLEAN) becomes 1 = 0.

    • simplifyFilterPredicates

      public @Nullable RexNode simplifyFilterPredicates(Iterable<? extends RexNode> predicates)
      Combines predicates AND, optimizes, and returns null if the result is always false.

      The expression is simplified on the assumption that an UNKNOWN value is always treated as FALSE. Therefore the simplified expression may sometimes evaluate to FALSE where the original expression would evaluate to UNKNOWN.

      Parameters:
      predicates - Filter condition predicates
      Returns:
      simplified conjunction of predicates for the filter, null if always false