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 MOD function #13502

Merged
merged 1 commit into from
Jan 7, 2024

Conversation

alexander-beedie
Copy link
Collaborator

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

Adds SQL support for MOD1 as a function, in addition to the existing support for the modulo % operator.

Example

import polars as pl

df = pl.DataFrame({
    "a": [1.5, None, 3.0, 10.0, 5.0],
    "b": [6, 7, 8, 9, None],
})
with pl.SQLContext(df=df) as ctx:
    out = ctx.execute(
        """
        SELECT
          a % 2 AS a_mod_2,
          MOD(b,3) AS b_mod_3,
        FROM df
        """
    ).collect()

    # shape: (5, 2)
    # ┌─────────┬─────────┐
    # │ a_mod_2 ┆ b_mod_3 │
    # │ ---     ┆ ---     │
    # │ f64     ┆ i64     │
    # ╞═════════╪═════════╡
    # │ 1.5     ┆ 0       │
    # │ null    ┆ 1       │
    # │ 1.0     ┆ 2       │
    # │ 0.0     ┆ 0       │
    # │ 1.0     ┆ null    │
    # └─────────┴─────────┘

Footnotes

  1. MOD function: https://www.postgresql.org/docs/current/functions-math.html#id-1.5.8.9.6.2.2.19.1.1.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 Jan 7, 2024
@alexander-beedie alexander-beedie added the A-sql Area: Polars SQL functionality label Jan 7, 2024
@stinodego
Copy link
Member

The next polars-cli release is going to be juicy!

@alexander-beedie
Copy link
Collaborator Author

alexander-beedie commented Jan 7, 2024

The next polars-cli release is going to be juicy!

And once #13491 goes in, I'm going to follow-up with looooong requested LIKE and ILIKE support too (already got it working locally). Make it a real party, heh 😎👍

@alexander-beedie alexander-beedie merged commit cb86827 into pola-rs:main Jan 7, 2024
31 checks passed
@alexander-beedie alexander-beedie deleted the sql-mod-function branch January 7, 2024 16:56
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