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: Fix use of COUNT(*) in SQL GROUP BY operations #16465

Merged
merged 1 commit into from
May 24, 2024

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented May 24, 2024

The difference between len/count caused the aggregate expression check in "GROUP BY" to miss len (it's not actually an AggExpr), as used by "COUNT(*)" in the SQL interface. Fixed, and added the missing coverage.

(Also includes two minor unrelated docstring updates).

Example

df = pl.DataFrame({
    "a": ["xx", "yy", "xx", "yy", "xx", "zz"],
    "b": [1, None, 3, 4, None, 6],
    "c": [99, 99, 66, 66, 66, 66],
})

df.sql("""
  SELECT
    a,
    COUNT(b) AS count_b,
    COUNT(*) AS count_star
  FROM self
  GROUP BY a
  ORDER BY a
""")

# shape: (3, 3)
# ┌─────┬─────────┬────────────┐
# │ a   ┆ count_b ┆ count_star │
# │ --- ┆ ---     ┆ ---        │
# │ str ┆ u32     ┆ u32        │
# ╞═════╪═════════╪════════════╡
# │ xx  ┆ 2       ┆ 3          │
# │ yy  ┆ 1       ┆ 2          │
# │ zz  ┆ 1       ┆ 1          │
# └─────┴─────────┴────────────┘

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels May 24, 2024
@alexander-beedie alexander-beedie added the A-sql Area: Polars SQL functionality label May 24, 2024
@alexander-beedie alexander-beedie force-pushed the sql-count-star-groupby branch 2 times, most recently from 8176ab9 to fcd8a8d Compare May 24, 2024 10:11
Copy link

codecov bot commented May 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.45%. Comparing base (d5f9c3b) to head (e611fa2).
Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16465      +/-   ##
==========================================
+ Coverage   81.42%   81.45%   +0.02%     
==========================================
  Files        1409     1409              
  Lines      184618   184726     +108     
  Branches     2971     2971              
==========================================
+ Hits       150334   150474     +140     
+ Misses      33764    33732      -32     
  Partials      520      520              

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

@ritchie46 ritchie46 merged commit c16c69a into pola-rs:main May 24, 2024
27 checks passed
@alexander-beedie alexander-beedie deleted the sql-count-star-groupby branch May 24, 2024 11:27
Wouittone pushed a commit to Wouittone/polars that referenced this pull request Jun 22, 2024
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.

None yet

2 participants