Skip to content

Reject recursive CTEs before processing the sub-expressions #3714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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