pub struct UnwrapCastInComparison {}Expand description
The rule can be used to the numeric binary comparison with literal expr, like below pattern:
cast(left_expr as data_type) comparison_op literal_expr or literal_expr comparison_op cast(right_expr as data_type).
The data type of two sides must be equal, and must be signed numeric type now, and will support more data type later.
If the binary comparison expr match above rules, the optimizer will check if the value of literal
is in within range(min,max) which is the range(min,max) of the data type for left_expr or right_expr.
If this is true, the literal expr will be casted to the data type of expr on the other side, and the result of
binary comparison will be left_expr comparison_op cast(literal_expr, left_data_type) or
cast(literal_expr, right_data_type) comparison_op right_expr. For better optimization,
the expr of cast(literal_expr, target_type) will be precomputed and converted to the new expr new_literal_expr
which data type is target_type.
If this false, do nothing.
This is inspired by the optimizer rule UnwrapCastInBinaryComparison of Spark.
Example
Filter: cast(c1 as INT64) > INT64(10) will be optimized to Filter: c1 > CAST(INT64(10) AS INT32), and continue to be converted to Filter: c1 > INT32(10)`, if the DataType of c1 is INT32.
Implementations
Trait Implementations
sourceimpl Default for UnwrapCastInComparison
impl Default for UnwrapCastInComparison
sourcefn default() -> UnwrapCastInComparison
fn default() -> UnwrapCastInComparison
sourceimpl OptimizerRule for UnwrapCastInComparison
impl OptimizerRule for UnwrapCastInComparison
sourcefn optimize(
&self,
plan: &LogicalPlan,
_optimizer_config: &mut OptimizerConfig
) -> Result<LogicalPlan>
fn optimize(
&self,
plan: &LogicalPlan,
_optimizer_config: &mut OptimizerConfig
) -> Result<LogicalPlan>
plan to an optimized form