Fischer0522 opened a new issue, #11901:
URL: https://github.com/apache/datafusion/issues/11901
### Describe the bug
ProjectionExec doesn't handle output schema when calling compute_properties()
### To Reproduce
Create ProjectionExec with an input plan and projection indexes, and then
call schema() of ProjectionExec(as ExecutionPlan), the result will mismatch
with output stream's schema
### Expected behavior
When creating ProjectionExec, it takes input stream and projects it, but it
doesn't project the input schema. the projection of schema should be handle
when calling `Self::compute_properties()` ->
`input_eq_properties.project(projection_mapping,schema)`. but it doesn't do any
projection on schema, just sets it as output schema in eq_properties. So, the
result mismatches
`input_eq_properties.project(projection_mapping,schema)` should project the
input schema and set the result in eq_properties.
### Additional context
Related code:
```rust
pub fn try_new(
expr: Vec<(Arc<dyn PhysicalExpr>, String)>,
input: Arc<dyn ExecutionPlan>,
) -> Result<Self> {
let input_schema = input.schema();
// ........
let projection_mapping = ProjectionMapping::try_new(&expr,
&input_schema)?;
let cache =
Self::compute_properties(&input, &projection_mapping,
Arc::clone(&schema))?;
Ok(Self {
expr,
schema,
input,
metrics: ExecutionPlanMetricsSet::new(),
cache,
})
}
/// This function creates the cache object that stores the plan
properties such as schema, equivalence properties, ordering, partitioning, etc.
fn compute_properties(
input: &Arc<dyn ExecutionPlan>,
projection_mapping: &ProjectionMapping,
schema: SchemaRef,
) -> Result<PlanProperties> {
// Calculate equivalence properties:
let mut input_eq_properties = input.equivalence_properties().clone();
input_eq_properties.substitute_oeq_class(projection_mapping)?;
let eq_properties = input_eq_properties.project(projection_mapping,
schema);
// .......
Ok(PlanProperties::new(
eq_properties,
output_partitioning,
input.execution_mode(),
))
}
// projection should be handle here
pub fn project(
&self,
projection_mapping: &ProjectionMapping,
output_schema: SchemaRef,
) -> Self {
let projected_constants =
self.projected_constants(projection_mapping);
let projected_eq_group = self.eq_group.project(projection_mapping);
let projected_orderings =
self.projected_orderings(projection_mapping);
Self {
eq_group: projected_eq_group,
oeq_class: OrderingEquivalenceClass::new(projected_orderings),
constants: projected_constants,
schema: output_schema,
}
}
```
--
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]