()
| 144 | |
| 145 | #[test] |
| 146 | fn test_simplify() { |
| 147 | let schema = test_schema(); |
| 148 | let simplifier = PhysicalExprSimplifier::new(&schema); |
| 149 | |
| 150 | // Create: cast(c2 as INT32) != INT32(99) |
| 151 | let column_expr = col("c2", &schema).unwrap(); |
| 152 | let cast_expr = Arc::new(CastExpr::new(column_expr, DataType::Int32, None)); |
| 153 | let literal_expr = lit(ScalarValue::Int32(Some(99))); |
| 154 | let binary_expr = |
| 155 | Arc::new(BinaryExpr::new(cast_expr, Operator::NotEq, literal_expr)); |
| 156 | |
| 157 | // Apply full simplification (uses TreeNodeRewriter) |
| 158 | let optimized = simplifier.simplify(binary_expr).unwrap(); |
| 159 | |
| 160 | let optimized_binary = as_binary(&optimized); |
| 161 | |
| 162 | // Should be optimized to: c2 != INT64(99) (c2 is INT64, literal cast to match) |
| 163 | let left_expr = optimized_binary.left(); |
| 164 | assert!( |
| 165 | left_expr.downcast_ref::<CastExpr>().is_none() |
| 166 | && left_expr.downcast_ref::<TryCastExpr>().is_none() |
| 167 | ); |
| 168 | let right_literal = as_literal(optimized_binary.right()); |
| 169 | assert_eq!(right_literal.value(), &ScalarValue::Int64(Some(99))); |
| 170 | } |
| 171 | |
| 172 | #[test] |
| 173 | fn test_nested_expression_simplification() { |
nothing calls this directly
no test coverage detected
searching dependent graphs…