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 RIGHT and REVERSE string functions #13461

Merged
merged 4 commits into from
Jan 5, 2024

Conversation

alexander-beedie
Copy link
Collaborator

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

Updates

  • We already support LEFT and SUBSTR; this PR adds the missing support for RIGHT.
  • Also adds support for the REVERSE string function.
  • As the primary SQL tests file recently exceeded 1000 lines, I channelled my inner @stinodego and overhauled the directory structure 😉 Instead of one large file it has been broken out into a set of fifteen. This will help identify weaker areas of coverage and better-organise future tests.

Example

import polars as pl

df = pl.DataFrame({"txt": ["abcdefg"]})

with pl.SQLContext({"data": df}) as sql:
    sql.execute(
        """
        SELECT 
          txt,
          LEFT(txt,3) AS "l", 
          RIGHT(txt,3) AS "r",
          REVERSE(txt) AS "rev"
        FROM data
        """,
        eager=True
    )
    # shape: (1, 4)
    # ┌─────────┬─────┬─────┬─────────┐
    # │ txt     ┆ l   ┆ r   ┆ rev     │
    # │ ---     ┆ --- ┆ --- ┆ ---     │
    # │ str     ┆ str ┆ str ┆ str     │
    # ╞═════════╪═════╪═════╪═════════╡
    # │ abcdefg ┆ abc ┆ efg ┆ gfedcba │
    # └─────────┴─────┴─────┴─────────┘

@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 5, 2024
@alexander-beedie alexander-beedie added the A-sql Area: Polars SQL functionality label Jan 5, 2024
@alexander-beedie alexander-beedie changed the title feat(rust,python,cli): add SQL engine support for RIGHT string function feat(rust,python,cli): add SQL engine support for RIGHT and REVERSE string functions Jan 5, 2024
@ritchie46 ritchie46 merged commit e66297a into pola-rs:main Jan 5, 2024
26 checks passed
@alexander-beedie alexander-beedie deleted the sql-right-string-func branch January 5, 2024 14:22
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