Skip to content

Commit

Permalink
Reject recursive CTEs before processing the sub-expressions (#3714)
Browse files Browse the repository at this point in the history
  • Loading branch information
isidentical authored Oct 5, 2022
1 parent d72eb9a commit 27f3e90
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions datafusion/sql/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,12 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
if let Some(with) = query.with {
// Process CTEs from top to bottom
// do not allow self-references
if with.recursive {
return Err(DataFusionError::NotImplemented(
"Recursive CTEs are not supported".to_string(),
));
}

for cte in with.cte_tables {
// A `WITH` block can't use the same name more than once
let cte_name = normalize_ident(&cte.alias.name);
Expand Down Expand Up @@ -3530,6 +3536,22 @@ mod tests {
);
}

#[test]
fn recursive_ctes() {
let sql = "
WITH RECURSIVE numbers AS (
select 1 as n
UNION ALL
select n + 1 FROM numbers WHERE N < 10
)
select * from numbers;";
let err = logical_plan(sql).expect_err("query should have failed");
assert_eq!(
r#"NotImplemented("Recursive CTEs are not supported")"#,
format!("{:?}", err)
);
}

#[test]
fn select_array_non_literal_type() {
let sql = "SELECT [now()]";
Expand Down

0 comments on commit 27f3e90

Please sign in to comment.