You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2026/05/01 05:40:41 UTC
(datafusion) branch gh-readonly-queue/main/pr-21885-ea0928c19ccfff9444ef3e5affd8c90e2db89e90 created (now d59bc7236b)
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a change to branch gh-readonly-queue/main/pr-21885-ea0928c19ccfff9444ef3e5affd8c90e2db89e90
in repository https://gitbox.apache.org/repos/asf/datafusion.git
at d59bc7236b fix(proto): correctly serialize FilterExec empty projection (#21885)
This branch includes the following new commits:
new d59bc7236b fix(proto): correctly serialize FilterExec empty projection (#21885)
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org
(datafusion) 01/01: fix(proto): correctly serialize FilterExec empty projection (#21885)
Posted by gi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-21885-ea0928c19ccfff9444ef3e5affd8c90e2db89e90
in repository https://gitbox.apache.org/repos/asf/datafusion.git
commit d59bc7236bf734492789fca3fabd77d7b8ace0c8
Author: aditya singh rathore <ra...@gmail.com>
AuthorDate: Fri May 1 11:10:19 2026 +0530
fix(proto): correctly serialize FilterExec empty projection (#21885)
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes #123` indicates that this PR will close issue #123.
-->
- Closes #21871
## Rationale for this change
FilterExec supports two semantically different projection states:
- None → return all columns (full projection)
- Some(vec![]) → return no columns (empty projection)
However, both cases were being serialized identically as an empty vector
in the proto representation. During deserialization, an empty vector was
always mapped back to None, meaning an empty projection would silently
become a full projection after a serde round-trip.
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->
No
<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->
---
datafusion/proto/src/physical_plan/mod.rs | 34 ++++++++++++--------
.../proto/tests/cases/roundtrip_physical_plan.rs | 37 ++++++++++++++++++++++
2 files changed, 58 insertions(+), 13 deletions(-)
diff --git a/datafusion/proto/src/physical_plan/mod.rs b/datafusion/proto/src/physical_plan/mod.rs
index 6145df6503..d4a83a76f3 100644
--- a/datafusion/proto/src/physical_plan/mod.rs
+++ b/datafusion/proto/src/physical_plan/mod.rs
@@ -716,18 +716,23 @@ impl protobuf::PhysicalPlanNode {
})?;
let filter_selectivity = filter.default_filter_selectivity.try_into();
- let projection = if !filter.projection.is_empty() {
- Some(
- filter
- .projection
- .iter()
- .map(|i| *i as usize)
- .collect::<Vec<_>>(),
- )
- } else {
+ // Preserve the `None` state across proto boundaries. Proto cannot distinguish
+ // between `None` (full projection) and `Some(vec![])` (empty projection) since
+ // both serialize as an empty list. If all columns are included, we reconstruct
+ // `None` to avoid losing this semantic distinction on deserialization.
+ let num_fields = input.schema().fields().len();
+ let mut is_full_projection = filter.projection.len() == num_fields;
+ let mut projection_vec: Vec<usize> = Vec::with_capacity(filter.projection.len());
+ for (i, idx) in filter.projection.iter().enumerate() {
+ let idx = *idx as usize;
+ is_full_projection &= idx == i;
+ projection_vec.push(idx);
+ }
+ let projection = if is_full_projection {
None
+ } else {
+ Some(projection_vec)
};
-
let filter = FilterExecBuilder::new(predicate, input)
.apply_projection(projection)?
.with_batch_size(filter.batch_size as usize)
@@ -2339,9 +2344,12 @@ impl protobuf::PhysicalPlanNode {
.physical_expr_to_proto(exec.predicate(), codec)?,
),
default_filter_selectivity: exec.default_selectivity() as u32,
- projection: exec.projection().as_ref().map_or_else(Vec::new, |v| {
- v.iter().map(|x| *x as u32).collect::<Vec<u32>>()
- }),
+ projection: match exec.projection() {
+ None => (0..exec.input().schema().fields().len())
+ .map(|i| i as u32)
+ .collect(),
+ Some(v) => v.iter().map(|x| *x as u32).collect(),
+ },
batch_size: exec.batch_size() as u32,
fetch: exec.fetch().map(|f| f as u32),
},
diff --git a/datafusion/proto/tests/cases/roundtrip_physical_plan.rs b/datafusion/proto/tests/cases/roundtrip_physical_plan.rs
index e7d38b57a1..8465c2a196 100644
--- a/datafusion/proto/tests/cases/roundtrip_physical_plan.rs
+++ b/datafusion/proto/tests/cases/roundtrip_physical_plan.rs
@@ -3681,3 +3681,40 @@ async fn roundtrip_issue_18602_complex_filter_decode_recursion() -> Result<()> {
roundtrip_test_sql_with_context(sql, &ctx).await
}
+
+#[test]
+fn roundtrip_filter_with_none_projection() -> Result<()> {
+ 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 predicate: Arc<dyn PhysicalExpr> = Arc::new(BinaryExpr::new(
+ Arc::new(Column::new("a", 0)),
+ Operator::Gt,
+ lit(ScalarValue::Int32(Some(0))),
+ ));
+ let input: Arc<dyn ExecutionPlan> = Arc::new(EmptyExec::new(Arc::clone(&schema)));
+
+ // Case 1: None projection (return all columns)
+ roundtrip_test(Arc::new(FilterExec::try_new(
+ Arc::clone(&predicate),
+ Arc::clone(&input),
+ )?))?;
+
+ // Case 2: Some(vec![]) — explicitly empty projection
+ roundtrip_test(Arc::new(
+ FilterExecBuilder::new(Arc::clone(&predicate), Arc::clone(&input))
+ .apply_projection(Some(vec![]))?
+ .build()?,
+ ))?;
+
+ // Case 3: Some(vec![2, 0]) — partial projection
+ roundtrip_test(Arc::new(
+ FilterExecBuilder::new(Arc::clone(&predicate), Arc::clone(&input))
+ .apply_projection(Some(vec![2, 0]))?
+ .build()?,
+ ))?;
+
+ Ok(())
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org