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(rust,python,cli): add SQL engine support for IFNULL function #13432

Merged
merged 1 commit into from
Jan 4, 2024

Conversation

alexander-beedie
Copy link
Collaborator

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

Support SQL "IFNULL" (equivalent to a two-argument "COALESCE").

Examples

import polars as pl

df = pl.DataFrame({
    "x": [1, None, 3],
    "y": [10, 20, 30],
})

pl.SQLContext(df=df).execute(
    """
    SELECT
      "x",
      IFNULL("x", "y") as "c1",
      IFNULL("x",-100) as "c2",
    FROM df
    """,
    eager=True,
)
# shape: (3, 3)
# ┌──────┬─────┬──────┐
# │ x    ┆ c1  ┆ c2   │
# │ ---  ┆ --- ┆ ---  │
# │ i64  ┆ i64 ┆ i64  │
# ╞══════╪═════╪══════╡
# │ 1    ┆ 1   ┆ 1    │
# │ null ┆ 20  ┆ -100 │
# │ 3    ┆ 3   ┆ 3    │
# └──────┴─────┴──────┘

@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 Jan 4, 2024
@alexander-beedie alexander-beedie added the A-sql Area: Polars SQL functionality label Jan 4, 2024
@ritchie46 ritchie46 merged commit d604987 into pola-rs:main Jan 4, 2024
26 checks passed
@alexander-beedie alexander-beedie deleted the sql-ifnull branch January 4, 2024 14:05
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