Expand description
Boolean and algebraic expression simplification Expression Simplification
This module provides boolean and expression simplification for SQL AST nodes. It applies various algebraic transformations to simplify expressions:
- De Morgan’s laws (NOT (A AND B) -> NOT A OR NOT B)
- Constant folding (1 + 2 -> 3)
- Boolean absorption (A AND (A OR B) -> A)
- Complement removal (A AND NOT A -> FALSE)
- Connector flattening (A AND (B AND C) -> A AND B AND C)
Based on SQLGlot’s optimizer/simplify.py
Structs§
- Simplifier
- Expression simplifier
Functions§
- absorb_
and_ eliminate_ and - Apply Boolean absorption and elimination rules to an AND expression
- absorb_
and_ eliminate_ or - Apply Boolean absorption and elimination rules to an OR expression
- always_
false - Check if expression is always false
- always_
true - Check if expression is always true
- bool_
false - Create a FALSE boolean literal
- bool_
true - Create a TRUE boolean literal
- eval_
boolean_ nums - Evaluate a boolean comparison between two numbers
- eval_
boolean_ strings - Evaluate a boolean comparison between two strings
- gen
- Generate a simple string representation of an expression for sorting/deduping
- is_
boolean_ false - Check if expression is a boolean FALSE literal (not just falsy)
- is_
boolean_ true - Check if expression is a boolean TRUE literal (not just truthy)
- is_
complement - Check if b is the complement of a (i.e., b = NOT a)
- is_
false - Check if expression is boolean FALSE
- is_null
- Check if expression is NULL
- is_zero
- Check if expression is zero
- null
- Create a NULL expression
- simplify
- Main entry point for expression simplification