Skip to content

Commit

Permalink
fix(python): Fix a global variable table-discovery edge case for the …
Browse files Browse the repository at this point in the history
…`SQL` interface (#17400)
  • Loading branch information
alexander-beedie authored Jul 3, 2024
1 parent 3a3600c commit 09c98c5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion py-polars/polars/sql/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def execute_global(
possible_names = (
{
nm.strip('"')
for nm in re.split(r"\s", q[1])
for nm in re.split(r"\b", q[1])
if re.match(r'^("[^"]+")$', nm) or nm.isidentifier()
}
if len(q) > 1
Expand Down
13 changes: 13 additions & 0 deletions py-polars/tests/unit/sql/test_miscellaneous.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,16 @@ def test_read_csv(tmp_path: Path) -> None:
match="`read_csv` expects a single file path; found 3 arguments",
):
pl.sql("SELECT * FROM read_csv('a','b','c')")


def test_global_variable_inference_17398() -> None:
users = pl.DataFrame({"id": "1"})

res = pl.sql(
query="""
WITH user_by_email AS (SELECT id FROM users)
SELECT * FROM user_by_email
""",
eager=True,
)
assert_frame_equal(res, users)

0 comments on commit 09c98c5

Please sign in to comment.