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(python,rust,cli): add SQL support for binary data and expand recognised SQL dtype strings #9802

Merged
merged 1 commit into from
Jul 10, 2023

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Jul 10, 2023

Adds SQL type support for Binary dtype, and recognition of additional PostgreSQL type strings such as double precision (Float64) and character varying (Utf8).

Example

The following now works:

import polars as pl

df = pl.DataFrame({
    "colx": [1, 2, 3],
    "coly": ["a", "b", "c"],
})

with pl.SQLContext( df=df, eager_execution=True ) as ctx:
    res = ctx.execute(
        """
        SELECT
          CAST(colx AS DOUBLE PRECISION) AS x_float,
          coly::varbinary AS y_binary,
        FROM df
        """
    )
    # ┌─────────┬───────────────┐
    # │ x_float ┆ y_binary      │
    # │ ---     ┆ ---           │
    # │ f64     ┆ binary        │
    # ╞═════════╪═══════════════╡
    # │ 1.0     ┆ [binary data] │
    # │ 2.0     ┆ [binary data] │
    # │ 3.0     ┆ [binary data] │
    # └─────────┴───────────────┘

res.to_dict(False)
# {
#   'x_float': [1.0, 2.0, 3.0], 
#   'y_binary': [b'a', b'b', b'c'],
# }

@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 Jul 10, 2023
@alexander-beedie alexander-beedie added A-sql Area: Polars SQL functionality cli labels Jul 10, 2023
@alexander-beedie alexander-beedie merged commit 0ac21fe into pola-rs:main Jul 10, 2023
@alexander-beedie alexander-beedie deleted the expand-sql-dtypes branch July 10, 2023 22:09
c-peters pushed a commit to c-peters/polars that referenced this pull request Jul 14, 2023
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