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

fix: preserve expression aliases when parsing SQL with pl.sql_expr #9875

Merged
merged 3 commits into from
Jul 14, 2023

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Jul 14, 2023

Coming at you from several kilometres up in the skies, somewhere over (I think?) Bosnia... :)

aerial_pull_request


Aliases were getting silently eaten when parsing SQL strings to Polars expressions; parsing as SelectItem instead of bare Expr allows any (optional) aliases to be captured and translated along with the underlying expression itself.

Example

Before:

pl.sql_expr( "MIN(a) as min_a" )
# col("a").min()

After:

pl.sql_expr( "MIN(a) as min_a" )
# col("a").min().alias("min_a")

Also:

Recognise power as an alias for pow ("power" is the usual PostgreSQL syntax, but I believe both are allowed).

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Jul 14, 2023
@alexander-beedie alexander-beedie added the A-sql Area: Polars SQL functionality label Jul 14, 2023
@alexander-beedie alexander-beedie force-pushed the sql-parse-aliased-exprs branch from 87dadbb to b114c25 Compare July 14, 2023 11:55
@ritchie46
Copy link
Member

Still topping our mile high record ;)

@ritchie46 ritchie46 merged commit e142383 into pola-rs:main Jul 14, 2023
@alexander-beedie alexander-beedie deleted the sql-parse-aliased-exprs branch July 14, 2023 12:53
@stinodego stinodego changed the title fix(python,rust,cli): preserve expression aliases when parsing SQL with pl.sql_expr fix: preserve expression aliases when parsing SQL with pl.sql_expr Jul 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql Area: Polars SQL functionality fix Bug fix python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants