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

ColumnNotFoundError occurs when ORDER BY references unaliased column in SQL query with aggregation #20428

Open
2 tasks done
BTatlock opened this issue Dec 23, 2024 · 0 comments
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars

Comments

@BTatlock
Copy link

BTatlock commented Dec 23, 2024

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

pl.DataFrame({"a": [1, 3, 2]}).sql("SELECT a b FROM self GROUP BY a ORDER BY a")

Log output

polars.exceptions.ColumnNotFoundError: "a" not found

Issue description

The column alias is expected by the ORDER BY query, meaning the following query works:

pl.DataFrame({"a": [1, 3, 2]}).sql("SELECT a b FROM self GROUP BY a ORDER BY b")

The unexpected behaviour is also seen when using fully qualified identifiers:

pl.DataFrame({"a": [1, 3, 2]}).sql("SELECT self.a b FROM self GROUP BY self.a ORDER BY self.a")

Expected behavior

Should be equivalent to

pl.DataFrame({"a": [1, 3, 2]}).sql("SELECT a FROM self GROUP BY a ORDER BY a").rename({"a": "b"})

Installed versions

--------Version info---------
Polars:              1.17.1
@BTatlock BTatlock added bug Something isn't working needs triage Awaiting prioritization by a maintainer python Related to Python Polars labels Dec 23, 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 needs triage Awaiting prioritization by a maintainer python Related to Python Polars
Projects
None yet
Development

No branches or pull requests

1 participant