Skip to content

optimize_projections fail due to difference schemas #8432

@haohuaijin

Description

@haohuaijin

Describe the bug

I run the follow sql in main 3ddd5eb , get the follow error

❯ create table t(x bigint, y bigint) as values (1,2), (1,3);
0 rows in set. Query took 0.011 seconds.

❯ select z+1, y from (select x+1 as z, y from t) where y > 1;
Optimizer rule 'optimize_projections' failed
caused by
optimize_projections
caused by
Internal error: Failed due to a difference in schemas, original schema: DFSchema { fields: [DFField { qualifier: None, field: Field { name: "z + Int64(1)", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} } }, DFField { qualifier: Some(Bare { table: "t" }), field: Field { name: "y", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} } }], metadata: {}, functional_dependencies: FunctionalDependencies { deps: [] } }, new schema: DFSchema { fields: [DFField { qualifier: None, field: Field { name: "t.x + Int64(1) + Int64(1)", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} } }, DFField { qualifier: Some(Bare { table: "t" }), field: Field { name: "y", data_type: Int64, nullable: true, dict_id: 0, dict_is_ordered: false, metadata: {} } }], metadata: {}, functional_dependencies: FunctionalDependencies { deps: [] } }.
This was likely caused by a bug in DataFusion's code and we would welcome that you file an bug report in our issue tracker

but it work in datafusion-cli v33

DataFusion CLI v33.0.0
❯ create table t(x bigint, y bigint) as values (1,2), (1,3);
0 rows in set. Query took 0.003 seconds.

❯ select z+1, y from (select x+1 as z, y from t) where y > 1;
+--------------+---+
| z + Int64(1) | y |
+--------------+---+
| 3            | 2 |
| 3            | 3 |
+--------------+---+
2 rows in set. Query took 0.006 seconds.

To Reproduce

No response

Expected behavior

No response

Additional context

looks like it is related to #8340

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions