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

feat: Support SQL ORDER BY ALL syntax #17212

Merged
merged 3 commits into from
Jun 28, 2024

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Jun 26, 2024

Continuing the recent onslaught of modern/friendly SQL syntax support...

  • SELECT * FROM df ORDER BY ALL

This syntax automatically orders by all columns found in the final selection1.
Can also apply DESC and NULLS FIRST/LAST modifiers, which get broadcast to all columns in the sort.

Example

This query...

pl.sql("""
  SELECT a, b, c, d, e, f, g FROM df
  ORDER BY 
    a DESC NULLS LAST, 
    b DESC NULLS LAST, 
    c DESC NULLS LAST,
    d DESC NULLS LAST, 
    e DESC NULLS LAST, 
    f DESC NULLS LAST,
    g DESC NULLS LAST
""")

...can now be written much more succinctly as:

pl.sql("""
  SELECT a, b, c, d, e, f, g FROM df 
  ORDER BY ALL DESC NULLS LAST
""")

Footnotes

  1. Note: if an actual column called "ALL" (irrespective of case) is present, that is prioritised.

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars labels Jun 26, 2024
@alexander-beedie alexander-beedie added the A-sql Area: Polars SQL functionality label Jun 26, 2024
Copy link

codecov bot commented Jun 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.81%. Comparing base (048c784) to head (672cde0).
Report is 7 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17212      +/-   ##
==========================================
- Coverage   80.82%   80.81%   -0.01%     
==========================================
  Files        1465     1466       +1     
  Lines      192039   192237     +198     
  Branches     2741     2745       +4     
==========================================
+ Hits       155211   155357     +146     
- Misses      36323    36375      +52     
  Partials      505      505              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ritchie46 ritchie46 merged commit 0bf045e into pola-rs:main Jun 28, 2024
27 checks passed
@alexander-beedie alexander-beedie deleted the sql-order-by-all branch June 28, 2024 09:02
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 enhancement New feature or an improvement of an existing feature 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