Skip to content

Commit 27f3e90

Browse files
authored
Reject recursive CTEs before processing the sub-expressions (#3714)
1 parent d72eb9a commit 27f3e90

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

datafusion/sql/src/planner.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,12 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
354354
if let Some(with) = query.with {
355355
// Process CTEs from top to bottom
356356
// do not allow self-references
357+
if with.recursive {
358+
return Err(DataFusionError::NotImplemented(
359+
"Recursive CTEs are not supported".to_string(),
360+
));
361+
}
362+
357363
for cte in with.cte_tables {
358364
// A `WITH` block can't use the same name more than once
359365
let cte_name = normalize_ident(&cte.alias.name);
@@ -3530,6 +3536,22 @@ mod tests {
35303536
);
35313537
}
35323538

3539+
#[test]
3540+
fn recursive_ctes() {
3541+
let sql = "
3542+
WITH RECURSIVE numbers AS (
3543+
select 1 as n
3544+
UNION ALL
3545+
select n + 1 FROM numbers WHERE N < 10
3546+
)
3547+
select * from numbers;";
3548+
let err = logical_plan(sql).expect_err("query should have failed");
3549+
assert_eq!(
3550+
r#"NotImplemented("Recursive CTEs are not supported")"#,
3551+
format!("{:?}", err)
3552+
);
3553+
}
3554+
35333555
#[test]
35343556
fn select_array_non_literal_type() {
35353557
let sql = "SELECT [now()]";

0 commit comments

Comments
 (0)