Enum RexUnknownAs

java.lang.Object
java.lang.Enum<RexUnknownAs>
org.apache.calcite.rex.RexUnknownAs
All Implemented Interfaces:
Serializable, Comparable<RexUnknownAs>, Constable

public enum RexUnknownAs extends Enum<RexUnknownAs>
Policy for whether a simplified expression may instead return another value.

In particular, it deals with converting three-valued logic (TRUE, FALSE, UNKNOWN) to two-valued logic (TRUE, FALSE) for callers that treat the UNKNOWN value the same as TRUE or FALSE.

Sometimes the three-valued version of the expression is simpler (has a smaller expression tree) than the two-valued version. In these cases, favor simplicity over reduction to two-valued logic.

See Also:
  • Enum Constant Details

    • FALSE

      public static final RexUnknownAs FALSE
      Policy that indicates that the expression is being used in a context Where an UNKNOWN value is treated in the same way as FALSE. Therefore, when simplifying the expression, it is acceptable for the simplified expression to evaluate to FALSE in some situations where the original expression would evaluate to UNKNOWN.

      SQL predicates (WHERE, ON, HAVING and FILTER (WHERE) clauses, a WHEN clause of a CASE expression, and in CHECK constraints) all treat UNKNOWN as FALSE.

      If the simplified expression never returns UNKNOWN, the simplifier should make this clear to the caller, if possible, by marking its type as BOOLEAN NOT NULL.

    • TRUE

      public static final RexUnknownAs TRUE
      Policy that indicates that the expression is being used in a context Where an UNKNOWN value is treated in the same way as TRUE. Therefore, when simplifying the expression, it is acceptable for the simplified expression to evaluate to TRUE in some situations where the original expression would evaluate to UNKNOWN.

      This does not occur commonly in SQL. However, it occurs internally during simplification. For example, "WHERE NOT expression" evaluates "NOT expression" in a context that treats UNKNOWN as FALSE; it is useful to consider that "expression" is evaluated in a context that treats UNKNOWN as TRUE.

      If the simplified expression never returns UNKNOWN, the simplifier should make this clear to the caller, if possible, by marking its type as BOOLEAN NOT NULL.

    • UNKNOWN

      public static final RexUnknownAs UNKNOWN
      Policy that indicates that the expression is being used in a context Where an UNKNOWN value is treated as is. This occurs:
      • In any expression whose type is not BOOLEAN
      • In BOOLEAN expressions that are NOT NULL
      • In BOOLEAN expressions where UNKNOWN should be returned as is, for example in a SELECT clause, or within an expression such as an operand to AND, OR or NOT

      If you are unsure, use UNKNOWN. It is the safest option.

  • Method Details

    • values

      public static RexUnknownAs[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static RexUnknownAs valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • falseIf

      public static RexUnknownAs falseIf(boolean unknownAsFalse)
      Returns FALSE if unknownAsFalse is true, UNKNOWN otherwise.
    • toBoolean

      public boolean toBoolean()
    • negate

      public RexUnknownAs negate()
    • or

      public RexUnknownAs or(RexUnknownAs other)
      Combines this with another RexUnknownAs in the same way as the three-valued logic of OR.

      For example, TRUE or FALSE returns TRUE; FALSE or UNKNOWN returns UNKNOWN.