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: Add SQL support for NULLS FIRST/LAST ordering #16711

Merged
merged 2 commits into from
Jun 5, 2024

Conversation

alexander-beedie
Copy link
Collaborator

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

Builds on #16639, integrating the new capability (per-column nulls first/last) as SQL.

Examples

import polars as pl

df = pl.DataFrame({
    "x": [2, 3, None, None],
    "y": [3, 2, None, 1],
})
df.sql("""
  SELECT * FROM self 
  ORDER BY x NULLS FIRST, y DESC NULLS LAST
""")
# shape: (4, 2)
# ┌──────┬──────┐
# │ x    ┆ y    │
# │ ---  ┆ ---  │
# │ i64  ┆ i64  │
# ╞══════╪══════╡
# │ null ┆ 1    │
# │ null ┆ null │
# │ 2    ┆ 3    │
# │ 3    ┆ 2    │
# └──────┴──────┘
df.sql("""
  SELECT * FROM self
  ORDER BY x DESC NULLS LAST, y NULLS FIRST
""")
# shape: (4, 2)
# ┌──────┬──────┐
# │ x    ┆ y    │
# │ ---  ┆ ---  │
# │ i64  ┆ i64  │
# ╞══════╪══════╡
# │ 3    ┆ 2    │
# │ 2    ┆ 3    │
# │ null ┆ null │
# │ null ┆ 1    │
# └──────┴──────┘

@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 4, 2024
@alexander-beedie alexander-beedie added the A-sql Area: Polars SQL functionality label Jun 4, 2024
@alexander-beedie alexander-beedie changed the title feat: Add SQL support for NULLS FIRST/LAST ordering directives feat: Add SQL support for NULLS FIRST/LAST ordering Jun 4, 2024
Copy link

codecov bot commented Jun 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.43%. Comparing base (a3d65df) to head (1ba22f1).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16711      +/-   ##
==========================================
- Coverage   81.45%   81.43%   -0.02%     
==========================================
  Files        1413     1413              
  Lines      186187   186188       +1     
  Branches     2776     2776              
==========================================
- Hits       151655   151623      -32     
- Misses      34012    34045      +33     
  Partials      520      520              

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

Copy link
Collaborator

@MarcoGorelli MarcoGorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't code I'd looked at before, but the logic looks very simple (and, as far as I can tell, correct)

Nitpick but it looks like now def foods_ipc_path happens in two places? Not an issue (and personally I'd prefer it this way, rather than having it magically happen in a conftest.py), just pointing it out

Copy link

codspeed-hq bot commented Jun 4, 2024

CodSpeed Performance Report

Merging #16711 will not alter performance

Comparing alexander-beedie:sql-nulls-first-last (1ba22f1) with main (a3d65df)

Summary

✅ 37 untouched benchmarks

@alexander-beedie
Copy link
Collaborator Author

Updated/rebased (yet again :))

@ritchie46 ritchie46 merged commit 0b48a93 into pola-rs:main Jun 5, 2024
26 checks passed
@alexander-beedie alexander-beedie deleted the sql-nulls-first-last branch June 5, 2024 11:59
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.

3 participants