kosiew commented on code in PR #25034:
URL: https://github.com/apache/datafusion/pull/25034#discussion_r4025533713


##########
datafusion/proto/tests/cases/plans/exprs.rs:
##########
@@ -286,6 +286,97 @@ fn roundtrip_call_null_scalar_struct_dict() -> Result<()> {
     roundtrip_test(filter)
 }
 
+#[test]
+fn roundtrip_binary_expr_overflow() -> Result<()> {
+    use arrow::record_batch::RecordBatch;
+    use datafusion_proto::bytes::{physical_plan_from_bytes, 
physical_plan_to_bytes};
+
+    let schema = Arc::new(Schema::empty());
+    let batch = RecordBatch::new_empty(Arc::clone(&schema));
+    for inner_checked in [false, true] {
+        for outer_checked in [false, true] {
+            // Overflow occurs in the inner addition. A different outer policy
+            // must not overwrite it when the encoder linearizes the chain.
+            let inner = Arc::new(
+                BinaryExpr::new(lit(i32::MAX), Operator::Plus, lit(1i32))
+                    .with_fail_on_overflow(inner_checked),
+            );
+            let expr: Arc<dyn PhysicalExpr> = Arc::new(
+                BinaryExpr::new(inner, Operator::Plus, lit(0i32))
+                    .with_fail_on_overflow(outer_checked),
+            );
+            let plan = Arc::new(ProjectionExec::try_new(
+                vec![(Arc::clone(&expr), "result".to_string())],
+                Arc::new(EmptyExec::new(Arc::clone(&schema))),
+            )?);
+            let bytes = physical_plan_to_bytes(plan)?;
+            let decoded =
+                physical_plan_from_bytes(&bytes, 
&SessionContext::new().task_ctx())?;
+            let decoded = decoded.downcast_ref::<ProjectionExec>().unwrap();
+            for expression in [&expr, &decoded.expr()[0].expr] {
+                let result = expression.evaluate(&batch);
+                if inner_checked {
+                    
assert!(result.unwrap_err().to_string().contains("overflow"));
+                } else {
+                    assert_eq!(
+                        result?.into_array(1)?.as_ref(),
+                        ScalarValue::Int32(Some(i32::MIN)).to_array()?.as_ref()
+                    );
+                }
+            }
+            assert!(expr.eq(&decoded.expr()[0].expr));
+        }
+    }
+    Ok(())
+}
+
+#[test]
+#[cfg(feature = "json")]
+fn roundtrip_binary_expr_overflow_legacy() -> Result<()> {

Review Comment:
   Could we also add a JSON roundtrip case for the current flattened `operands` 
representation with `failOnOverflow: true`? Right now this test covers JSON 
through the legacy `l`/`r` shape, while normal encoding emits `operands`. 
Covering that form would exercise the updated pbjson handling through the same 
representation used by current production encoding.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to