MCPcopy Create free account
hub / github.com/apache/datafusion / test_simplify

Function test_simplify

datafusion/physical-expr/src/simplifier/mod.rs:146–170  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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() {

Callers

nothing calls this directly

Calls 9

newFunction · 0.85
as_binaryFunction · 0.85
as_literalFunction · 0.85
test_schemaFunction · 0.70
colFunction · 0.50
litFunction · 0.50
simplifyMethod · 0.45
leftMethod · 0.45
rightMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…