gruuya commented on issue #8008:
URL:
https://github.com/apache/arrow-datafusion/issues/8008#issuecomment-1792456186
To make this more concrete, here's a test (e.g. in
`datafusion/optimizer/src/common_subexpr_eliminate.rs`) that demonstrates the
issue
```rust
#[test]
fn plan_schema_changed() -> Result<()> {
let original_plan = test_table_scan()?;
// Transformed plan, that has columns renamed
let new_plan = LogicalPlanBuilder::from(original_plan.clone())
.aggregate(vec![col("a")], vec![max(col("b")), min(col("c"))])?
.build()?;
// Attempt to rename columns to original
let projection_plan = LogicalPlanBuilder::from(new_plan)
.project(vec![
col("a"),
col("MAX(test.b)").alias("b"),
col("MIN(test.c)").alias("c"),
])?
.build()?;
// This will fail since the qualifiers are stripped when building a
schema from any expression other than `Expr::Column`
assert_eq!(
original_plan.schema(),
projection_plan.schema(),
);
Ok(())
}
```
This fails with:
```text
assertion `left == right` failed
left: DFSchema { fields: [DFField { qualifier: Some(Bare { table: "test"
}), field: Field { name: "a", data_type: UInt32, nullable: false, dict_id: 0,
dict_is_ordered: false, metadata: {} } }, DFField { qualifier: Some(Bare {
table: "test" }), field: Field { name: "b", data_type: UInt32, nullable: false,
dict_id: 0, dict_is_ordered: false, metadata: {} } }, DFField { qualifier:
Some(Bare { table: "test" }), field: Field { name: "c", data_type: UInt32,
nullable: false, dict_id: 0, dict_is_ordered: false, metadata: {} } }],
metadata: {}, functional_dependencies: FunctionalDependencies { deps: [] } }
right: DFSchema { fields: [DFField { qualifier: Some(Bare { table: "test"
}), field: Field { name: "a", data_type: UInt32, nullable: false, dict_id: 0,
dict_is_ordered: false, metadata: {} } }, DFField { qualifier: None, field:
Field { name: "b", data_type: UInt32, nullable: true, dict_id: 0,
dict_is_ordered: false, metadata: {} } }, DFField { qualifier: None, field:
Field { name: "c", data_type: UInt32, nullable: true, dict_id: 0,
dict_is_ordered: false, metadata: {} } }], metadata: {},
functional_dependencies: FunctionalDependencies { deps: [FunctionalDependence {
source_indices: [0], target_indices: [0, 1, 2], nullable: false, mode: Single
}] } }
```
Note that above the functional dependencies are also different, but that is
not what is [being
asserted](https://github.com/apache/arrow-datafusion/blob/main/datafusion/optimizer/src/optimizer.rs#L427-L452)
in-between optimization runs.
--
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]