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 REPLACE string function #13431

Merged
merged 1 commit into from
Jan 5, 2024

Conversation

alexander-beedie
Copy link
Collaborator

Adds SQL support for "REPLACE" (equivalent to polars replace_all when "literal=True").

Example

import polars as pl

df = pl.DataFrame({"txt": ["Yemeni coffee is the best coffee"]})

with pl.SQLContext(df=df) as ctx:
    out = ctx.execute(
        """
        SELECT *,
          REPLACE(
            REPLACE(txt, 'coffee', 'tea'),
            'Yemeni',
            'English breakfast'
          ) AS "updated"
        FROM df
        """
    ).collect()

with pl.Config( fmt_str_lengths=50 ):
    print(out)
    
    # shape: (1, 2)
    # ┌──────────────────────────────────┬───────────────────────────────────────┐
    # │ txt                              ┆ updated                               │
    # │ ---                              ┆ ---                                   │
    # │ str                              ┆ str                                   │
    # ╞══════════════════════════════════╪═══════════════════════════════════════╡
    # │ Yemeni coffee is the best coffee ┆ English breakfast tea is the best tea │
    # └──────────────────────────────────┴───────────────────────────────────────┘

@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
@ritchie46
Copy link
Member

How do you find them all?

@ritchie46 ritchie46 merged commit cbfa5cf into pola-rs:main Jan 5, 2024
26 checks passed
@alexander-beedie
Copy link
Collaborator Author

alexander-beedie commented Jan 5, 2024

How do you find them all?

This helps: #7227. I go back to that semi-regularly to grab things off the pile (or add to it); there is no shortage of things to add, so I usually take on the more obviously useful or easy to implement functions first ;)

@alexander-beedie alexander-beedie deleted the sql-string-replace branch January 5, 2024 10:29
@alexander-beedie alexander-beedie added the A-sql Area: Polars SQL functionality label Jan 7, 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 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