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

Distinct on expressions mismatch ORDER BY expressions because of a qualified column #13038

Open
epsio-banay opened this issue Oct 21, 2024 · 0 comments · May be fixed by #13039
Open

Distinct on expressions mismatch ORDER BY expressions because of a qualified column #13038

epsio-banay opened this issue Oct 21, 2024 · 0 comments · May be fixed by #13039
Labels
bug Something isn't working

Comments

@epsio-banay
Copy link
Contributor

Describe the bug

When planning a query with distinct on, the distinct on expressions must match the order by expressions.
There is a check for that, however the check checks if the expressions are equal without normalizing column names first.
Because of that planning queries like "SELECT DISTINCT ON (t.a) * FROM t ORDER BY a" won't work while ""SELECT DISTINCT ON (t.a) * FROM t ORDER BY t.a" will.

To Reproduce

Add the following to plan.rs unit tests and run:

#[test]
    fn distinct_on_expr_order_by_match() -> Result<()> {
        let schema = Schema::new(vec![Field::new("a", DataType::Int32, false)]);

        let table_scan =
            table_scan(Some(TableReference::bare("t")), &schema, None)?.build()?;
        let p = DistinctOn::try_new(
            vec![col("a")],
            vec![],
            Some(vec![SortExpr::new(col("t.a"), true, false)]),
            Arc::new(table_scan),
        )?;
        Ok(())
    }

Expected behavior

Test should pass

Additional context

No response

@epsio-banay epsio-banay added the bug Something isn't working label Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant