@@ -1403,6 +1403,35 @@ fn recursive_ctes() {
1403
1403
) ;
1404
1404
}
1405
1405
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
+
1406
1435
#[ test]
1407
1436
fn select_simple_aggregate_with_groupby_and_column_is_in_aggregate_and_groupby ( ) {
1408
1437
quick_test (
@@ -2696,6 +2725,12 @@ struct MockContextProvider {
2696
2725
udafs : HashMap < String , Arc < AggregateUDF > > ,
2697
2726
}
2698
2727
2728
+ impl MockContextProvider {
2729
+ fn options_mut ( & mut self ) -> & mut ConfigOptions {
2730
+ & mut self . options
2731
+ }
2732
+ }
2733
+
2699
2734
impl ContextProvider for MockContextProvider {
2700
2735
fn get_table_source ( & self , name : TableReference ) -> Result < Arc < dyn TableSource > > {
2701
2736
let schema = match name. table ( ) {
@@ -2805,6 +2840,14 @@ impl ContextProvider for MockContextProvider {
2805
2840
fn options ( & self ) -> & ConfigOptions {
2806
2841
& self . options
2807
2842
}
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
+ }
2808
2851
}
2809
2852
2810
2853
#[ test]
0 commit comments