Skip to content

Conversation

@alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Dec 4, 2025

Closes #21180.

This syntax represents a simple lateral unnest (explode) against the left join table and the referenced column, so this PR adds a small/dedicated path for handling it. Added suitable test coverage.

Example

import polars as pl

df = pl.DataFrame({
    "id": ["xyz", "abc"],
    "items": [[100, 200], [300, 400, 500]],
})

df.sql("""
  SELECT id, item
  FROM self CROSS JOIN UNNEST(items) AS item
  ORDER BY id DESC, item ASC
""")
# shape: (5, 2)
# ┌─────┬──────┐
# │ id  ┆ item │
# │ --- ┆ ---  │
# │ str ┆ i64  │
# ╞═════╪══════╡
# │ xyz ┆ 100  │
# │ xyz ┆ 200  │
# │ abc ┆ 300  │
# │ abc ┆ 400  │
# │ abc ┆ 500  │
# └─────┴──────┘

Also: automatic pytest.skip if running tests locally that use assert_sql_matches with duckdb, if duckdb is not installed (note: will always be available on CI).

@github-actions github-actions bot added 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 labels Dec 4, 2025
@alexander-beedie alexander-beedie force-pushed the sql-cross-join-unnest branch 3 times, most recently from 7e16c27 to 0ac8d9a Compare December 4, 2025 12:49
@alexander-beedie alexander-beedie marked this pull request as draft December 4, 2025 12:50
@alexander-beedie alexander-beedie marked this pull request as ready for review December 4, 2025 12:57
@codecov
Copy link

codecov bot commented Dec 4, 2025

Codecov Report

❌ Patch coverage is 88.33333% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.53%. Comparing base (cba9324) to head (34cb152).

Files with missing lines Patch % Lines
crates/polars-sql/src/context.rs 88.33% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #25623      +/-   ##
==========================================
+ Coverage   79.49%   79.53%   +0.03%     
==========================================
  Files        1742     1742              
  Lines      240147   240207      +60     
  Branches     3038     3038              
==========================================
+ Hits       190909   191049     +140     
+ Misses      48455    48375      -80     
  Partials      783      783              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Support SQL CROSS JOIN UNNEST(...)

1 participant