Skip to content

UnwrapCastInComparison exist bug #4430

@jackwener

Description

@jackwener

Describe the bug

called `Result::unwrap()` on an `Err` value: 
Internal("Optimizer rule 'unwrap_cast_in_comparison' failed due to unexpected error: 
Schema error: No field named 'test.col_int32 + test.col_uint32'. Valid fields are 'test'.'col_int32', 'test'.'col_uint32', 'test'.'col_utf8', 'test'.'col_date32', 'test'.'col_date64', 'test'.'col_ts_nano_none', 'test'.'col_ts_nano_utc'.")

To Reproduce
run in optimizer integration-test

#[test]
fn push_down_filter_groupby_expr_contains_alias() {
    let sql = "SELECT * FROM (SELECT (col_int32 + col_uint32) AS c, count(*) FROM test GROUP BY 1) where c > 3";
    let plan = test_sql(sql).unwrap();
    let expected = "Projection: c, COUNT(UInt8(1))\
    \n  Projection: test.col_int32 + test.col_uint32 AS c, COUNT(UInt8(1))\
    \n    Aggregate: groupBy=[[test.col_int32 + CAST(test.col_uint32 AS Int32)]], aggr=[[COUNT(UInt8(1))]]\
    \n      Filter: CAST(test.col_int32 + test.col_uint32 AS Int64) > Int64(3)\
    \n        TableScan: test projection=[col_int32, col_uint32]";
    assert_eq!(expected, format!("{:?}", plan));
}

Expected behavior
A clear and concise description of what you expected to happen.

Additional context
Add any other context about the problem here.

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