Adez017 commented on code in PR #21885:
URL: https://github.com/apache/datafusion/pull/21885#discussion_r3154618983


##########
datafusion/proto/tests/cases/roundtrip_physical_plan.rs:
##########
@@ -3681,3 +3681,63 @@ async fn 
roundtrip_issue_18602_complex_filter_decode_recursion() -> Result<()> {
 
     roundtrip_test_sql_with_context(sql, &ctx).await
 }
+
+#[tokio::test]
+async fn test_filter_exec_projection_serde_roundtrip() -> Result<()> {
+    let ctx = SessionContext::new();
+    let codec = DefaultPhysicalExtensionCodec {};
+
+    let schema = Arc::new(Schema::new(vec![
+        Field::new("a", DataType::Int32, false),
+        Field::new("b", DataType::Int32, false),
+        Field::new("c", DataType::Int32, false),
+    ]));
+
+    let input: Arc<dyn ExecutionPlan> = 
Arc::new(EmptyExec::new(Arc::clone(&schema)));
+
+    let predicate: Arc<dyn PhysicalExpr> = Arc::new(BinaryExpr::new(
+        Arc::new(Column::new("a", 0)),
+        Operator::Gt,
+        Arc::new(Literal::new(ScalarValue::Int32(Some(0)))),
+    ));
+
+    // Case 1: None -> should round-trip as None (return all columns)
+    let filter =
+        FilterExecBuilder::new(Arc::clone(&predicate), 
Arc::clone(&input)).build()?;
+    let proto = PhysicalPlanNode::try_from_physical_plan(Arc::new(filter) as 
_, &codec)?;
+    let roundtripped = proto.try_into_physical_plan(ctx.task_ctx().as_ref(), 
&codec)?;
+    let rt = roundtripped.as_ref().downcast_ref::<FilterExec>().unwrap();
+    assert_eq!(
+        rt.projection().as_deref(),
+        None,
+        "None projection must stay None after roundtrip"
+    );
+

Review Comment:
   The issue occurs because when a `FilterExec` has an empty projection, the 
previous proto serialization didn't explicitly encode the 'empty' state. This 
caused the physical plan to default back to a full projection or an invalid 
state upon deserialization. By explicitly handling the projection field even 
when empty, we ensure that the execution plan remains consistent across the 
network/serde boundary, which is critical for count-only queries.



-- 
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