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

fix: Raise error instead of panicking for unsupported SQL operations #20789

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions crates/polars-sql/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,6 @@ impl SQLContext {
}
},
op => {
let op = match op {
SetExpr::SetOperation { op, .. } => op,
_ => unreachable!(),
};
polars_bail!(SQLInterface: "'{}' operation is currently unsupported", op)
},
}
Expand Down
48 changes: 48 additions & 0 deletions py-polars/tests/unit/sql/test_set_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,54 @@ def test_except_intersect_all_unsupported(op: str, op_subtype: str) -> None:
pl.sql(f"SELECT * FROM df1 {op} {op_subtype} SELECT * FROM df2")


def test_update_statement_error() -> None:
df_large = pl.DataFrame(
{
"FQDN": ["c.ORG.na", "a.COM.na"],
"NS1": ["ns1.c.org.na", "ns1.d.net.na"],
"NS2": ["ns2.c.org.na", "ns2.d.net.na"],
"NS3": ["ns3.c.org.na", "ns3.d.net.na"],
}
)
df_small = pl.DataFrame(
{
"FQDN": ["c.org.na"],
"NS1": ["ns1.c.org.na|127.0.0.1"],
"NS2": ["ns2.c.org.na|127.0.0.1"],
"NS3": ["ns3.c.org.na|127.0.0.1"],
}
)

# Create a context and register the tables
ctx = pl.SQLContext()
ctx.register("large", df_large)
ctx.register("small", df_small)

with pytest.raises(
SQLInterfaceError,
match="'UPDATE large SET FQDN = u.FQDN, NS1 = u.NS1, NS2 = u.NS2, NS3 = u.NS3 FROM u WHERE large.FQDN = u.FQDN' operation is currently unsupported",
):
ctx.execute("""
WITH u AS (
SELECT
small.FQDN,
small.NS1,
small.NS2,
small.NS3
FROM small
INNER JOIN large ON small.FQDN = large.FQDN
)
UPDATE large
SET
FQDN = u.FQDN,
NS1 = u.NS1,
NS2 = u.NS2,
NS3 = u.NS3
FROM u
WHERE large.FQDN = u.FQDN
""")


@pytest.mark.parametrize("op", ["EXCEPT", "INTERSECT", "UNION"])
def test_except_intersect_errors(op: str) -> None:
df1 = pl.DataFrame({"x": [1, 9, 1, 1], "y": [2, 3, 4, 4], "z": [5, 5, 5, 5]}) # noqa: F841
Expand Down
Loading