Skip to content

Commit

Permalink
add test for unsupported update query
Browse files Browse the repository at this point in the history
the test may be more complicated than required, but I wanted to base the test case on the bug report here - dathere/qsv#2450
  • Loading branch information
jqnatividad committed Jan 22, 2025
1 parent 8e58e23 commit 97986a5
Showing 1 changed file with 48 additions and 0 deletions.
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(
{ # noqa: F841
"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(
{ # noqa: F841
"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

0 comments on commit 97986a5

Please sign in to comment.