Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression in simplifying expressions in subqueries #3760

Closed
andygrove opened this issue Oct 7, 2022 · 0 comments · Fixed by #3764
Closed

Regression in simplifying expressions in subqueries #3760

andygrove opened this issue Oct 7, 2022 · 0 comments · Fixed by #3764
Labels
bug Something isn't working optimizer Optimizer rules

Comments

@andygrove
Copy link
Member

andygrove commented Oct 7, 2022

Describe the bug
We hit a regression in Dask SQL after upgrading to 13.0.0-rc1 (dask-contrib/dask-sql#844).

Example query:

SELECT col_int32 FROM test
    WHERE col_int32 > (
      SELECT AVG(col_int32) FROM test
      WHERE col_utf8 BETWEEN '2002-05-08'
        AND (cast('2002-05-08' as date) + interval '5 days')
    )

Expected Filter

Filter: test.col_utf8 BETWEEN Utf8("2002-05-08") AND Utf8("2002-05-13")

Actual Filter

Filter: test.col_utf8 BETWEEN Utf8("2002-05-08") AND CAST(CAST(Utf8("2002-05-08") AS Date32) + IntervalDayTime("21474836480") AS Utf8)

To Reproduce
Here is a repro for the optimizer integration-test.rs:

#[test]
fn subquery_filter_with_cast() -> Result<()> {
    let sql = "SELECT col_int32 FROM test \
    WHERE col_int32 > (\
      SELECT AVG(col_int32) FROM test \
      WHERE col_utf8 BETWEEN '2002-05-08' \
        AND (cast('2002-05-08' as date) + interval '5 days')\
    )";
    let plan = test_sql(sql)?;
    let expected =
        "Projection: test.col_int32\n  Filter: CAST(test.col_int32 AS Float64) > __sq_1.__value\
        \n    CrossJoin:\n      TableScan: test projection=[col_int32]\
        \n      Projection: AVG(test.col_int32) AS __value, alias=__sq_1\
        \n        Aggregate: groupBy=[[]], aggr=[[AVG(test.col_int32)]]\
        \n          Filter: test.col_utf8 BETWEEN Utf8(\"2002-05-08\") AND Utf8(\"2002-05-13\")\
        \n            TableScan: test projection=[col_int32, col_utf8]";
    assert_eq!(expected, format!("{:?}", plan));
    Ok(())
}

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

Additional context
Add any other context about the problem here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working optimizer Optimizer rules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant