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!: Dedicated SQLInterface and SQLSyntax errors #16635

Merged
merged 1 commit into from
Jun 4, 2024

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented May 31, 2024

As previously discussed, this implements dedicated SQL-specific errors.
(Currently it's a mix of ComputeError and InvalidOperation).

New errors:

  • SQLSyntaxError: otherwise-supported syntax that was used incorrectly (for example: incorrect number of parameters passed to a valid SQL function).
  • SQLInterfaceError: almost every other error that can come specifically from the SQL interface (unimplemented functions, references to unregistered tables, etc).

Also:

  • Updates syntax errors such that they reference the actual SQL function name, not the internal parser Enum (eg: "ARRAY_TO_STRING" instead of "ArrayToString").

Examples

  • Syntax errors:

    (function only expects 1-2 parameters)
    import polars as pl
    df = pl.DataFrame({"n": [5.55, -10.0, 66.999]})
    
    df.sql("SELECT ROUND(n,1,2,3) FROM self")
    # SQLSyntaxError:
    #  invalid number of arguments for ROUND; expected 1 or 2, found 4
    (incorrect parameter type)
    df.sql("SELECT ROUND(n,'aaaa') FROM self")
    # SQLSyntaxError:
    #  invalid 'n_decimals' for ROUND ('aaaa')
  • Interface error:

    (syntax is fine, but no such table was registered)
    pl.sql("SELECT * FROM some_unknown_table")
    # SQLInterfaceError:
    #  relation 'some_unknown_table' was not found

@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 May 31, 2024
@alexander-beedie alexander-beedie added the A-sql Area: Polars SQL functionality label May 31, 2024
@alexander-beedie alexander-beedie changed the title feat: Add dedicated SQLInterface and SQLSyntax errors feat: Dedicated SQLInterface and SQLSyntax errors May 31, 2024
Copy link

codecov bot commented May 31, 2024

Codecov Report

Attention: Patch coverage is 43.47826% with 91 lines in your changes are missing coverage. Please review.

Project coverage is 81.51%. Comparing base (5974ac7) to head (4c636e3).
Report is 5 commits behind head on main.

Files Patch % Lines
crates/polars-sql/src/sql_expr.rs 35.93% 41 Missing ⚠️
crates/polars-sql/src/functions.rs 43.18% 25 Missing ⚠️
crates/polars-sql/src/context.rs 42.85% 20 Missing ⚠️
crates/polars-sql/src/table_functions.rs 57.14% 3 Missing ⚠️
crates/polars-error/src/lib.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16635      +/-   ##
==========================================
- Coverage   81.51%   81.51%   -0.01%     
==========================================
  Files        1414     1414              
  Lines      185995   186010      +15     
  Branches     3026     3026              
==========================================
+ Hits       151608   151620      +12     
- Misses      33856    33859       +3     
  Partials      531      531              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ritchie46
Copy link
Member

Nice, I will wait until we can move the breaking PR's.

@ritchie46 ritchie46 added the breaking Change that breaks backwards compatibility label Jun 1, 2024
@stinodego stinodego changed the title feat: Dedicated SQLInterface and SQLSyntax errors feat!: Dedicated SQLInterface and SQLSyntax errors Jun 2, 2024
@ritchie46 ritchie46 merged commit 889b00a into pola-rs:main Jun 4, 2024
39 checks passed
@alexander-beedie alexander-beedie deleted the sql-exceptions branch June 4, 2024 08:58
@stinodego stinodego added the skip changelog Do not include in changelog label Jun 12, 2024
@stinodego stinodego removed breaking Change that breaks backwards compatibility skip changelog Do not include in changelog labels Jun 12, 2024
@github-actions github-actions bot added the breaking Change that breaks backwards compatibility label Jun 12, 2024
@stinodego stinodego removed the breaking Change that breaks backwards compatibility label Jun 12, 2024
Wouittone pushed a commit to Wouittone/polars that referenced this pull request Jun 22, 2024
@github-actions github-actions bot added the breaking Change that breaks backwards compatibility label Jul 2, 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 breaking Change that breaks backwards compatibility 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.

3 participants