Skip to content

Commit

Permalink
fix: Handle quoted identifiers when registering CTEs in the SQL engine (
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-beedie authored Apr 10, 2024
1 parent 97c61fe commit c2bcd12
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion crates/polars-sql/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ impl SQLContext {
polars_bail!(ComputeError: "recursive CTEs are not supported")
}
for cte in &with.cte_tables {
let cte_name = cte.alias.name.to_string();
let cte_name = cte.alias.name.value.clone();
let cte_lf = self.execute_query(&cte.query)?;
self.register_cte(&cte_name, cte_lf);
}
Expand Down
18 changes: 9 additions & 9 deletions crates/polars-sql/tests/simple_exprs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,15 +448,15 @@ fn test_ctes() -> PolarsResult<()> {
let mut context = SQLContext::new();
context.register("df", df.lazy());

let sql = r#"
with df0 as (
SELECT * FROM df
)
select * from df0 "#;
assert!(context.execute(sql).is_ok());

let sql = r#"select * from df0"#;
assert!(context.execute(sql).is_err());
// note: confirm correct behaviour of quoted/unquoted CTE identifiers
let sql0 = r#"WITH "df0" AS (SELECT * FROM "df") SELECT * FROM df0 "#;
assert!(context.execute(sql0).is_ok());

let sql1 = r#"WITH df0 AS (SELECT * FROM df) SELECT * FROM "df0" "#;
assert!(context.execute(sql1).is_ok());

let sql2 = r#"SELECT * FROM df0"#;
assert!(context.execute(sql2).is_err());

Ok(())
}
Expand Down

0 comments on commit c2bcd12

Please sign in to comment.