Skip to content

Commit f13701f

Browse files
committed
wip: add sql test for logical plan
1 parent 915569b commit f13701f

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

datafusion/sql/src/planner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub trait ContextProvider {
6767
_name: &str,
6868
_schema: SchemaRef,
6969
) -> Result<Arc<dyn TableSource>> {
70-
not_impl_err!("Recursive CTE is not supported")
70+
not_impl_err!("Recursive CTE is not implemented")
7171
}
7272

7373
/// Getter for a UDF description

datafusion/sql/tests/sql_integration.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,6 +1403,35 @@ fn recursive_ctes() {
14031403
);
14041404
}
14051405

1406+
#[test]
1407+
fn recursive_ctes_enabled() {
1408+
let sql = "
1409+
WITH RECURSIVE numbers AS (
1410+
select 1 as n
1411+
UNION ALL
1412+
select n + 1 FROM numbers WHERE N < 10
1413+
)
1414+
select * from numbers;";
1415+
1416+
// manually setting up test here so that we can enable recursive ctes
1417+
let mut context = MockContextProvider::default();
1418+
context.options_mut().execution.enable_recursive_ctes = true;
1419+
1420+
let planner = SqlToRel::new_with_options(&context, ParserOptions::default());
1421+
let result = DFParser::parse_sql_with_dialect(sql, &GenericDialect {});
1422+
let mut ast = result.unwrap();
1423+
1424+
let plan = planner
1425+
.statement_to_plan(ast.pop_front().unwrap())
1426+
.expect("recursive cte plan creation failed");
1427+
1428+
assert_eq!(
1429+
format!("{plan:?}"),
1430+
"Projection: numbers.n
1431+
SubqueryAlias: numbers\n RecursiveQuery: is_distinct=false\n Projection: Int64(1) AS n\n EmptyRelation\n Projection: numbers.n + Int64(1)\n Filter: numbers.n < Int64(10)\n TableScan: numbers"
1432+
);
1433+
}
1434+
14061435
#[test]
14071436
fn select_simple_aggregate_with_groupby_and_column_is_in_aggregate_and_groupby() {
14081437
quick_test(
@@ -2696,6 +2725,12 @@ struct MockContextProvider {
26962725
udafs: HashMap<String, Arc<AggregateUDF>>,
26972726
}
26982727

2728+
impl MockContextProvider {
2729+
fn options_mut(&mut self) -> &mut ConfigOptions {
2730+
&mut self.options
2731+
}
2732+
}
2733+
26992734
impl ContextProvider for MockContextProvider {
27002735
fn get_table_source(&self, name: TableReference) -> Result<Arc<dyn TableSource>> {
27012736
let schema = match name.table() {
@@ -2805,6 +2840,14 @@ impl ContextProvider for MockContextProvider {
28052840
fn options(&self) -> &ConfigOptions {
28062841
&self.options
28072842
}
2843+
2844+
fn create_cte_work_table(
2845+
&self,
2846+
_name: &str,
2847+
schema: SchemaRef,
2848+
) -> Result<Arc<dyn TableSource>> {
2849+
Ok(Arc::new(EmptyTable::new(schema)))
2850+
}
28082851
}
28092852

28102853
#[test]

0 commit comments

Comments
 (0)