jonahgao opened a new pull request, #9795:
URL: https://github.com/apache/arrow-datafusion/pull/9795

   ## Which issue does this PR close?
   Closes #9794.
   
   ## Rationale for this change
   Make the schema of the recursive term compatible with  the static term.
   
   This differs from the handling of the ordinary 
[union](https://github.com/apache/arrow-datafusion/blob/ad89ff82421e9c4670f4440dd5a6fa6fb55c40c3/datafusion/expr/src/logical_plan/builder.rs#L1323)
 operator. We can't change the static term's schema, otherwise we would have to 
recreate the logic plan of the recursive term, as it depends on the static term 
through the work table.
   
   That is to say, we use the schema of the static term as the final schema for 
CTE. 
   DuckDB also adopted a similar approach.
   ```sh
   D WITH RECURSIVE my_cte AS(
           SELECT 1::int AS a
           UNION ALL
           SELECT a::bigint+2 FROM my_cte WHERE a<3
       ) SELECT a,typeof(a) FROM my_cte;
   ┌───────┬───────────┐
   │   a   │ typeof(a) │
   │ int32 │  varchar  │
   ├───────┼───────────┤
   │     1 │ INTEGER   │
   │     3 │ INTEGER   │
   └───────┴───────────┘
   ```
   The output type is `INTEGER` from the static term, not `BIGINT`.
   
   ## What changes are included in this PR?
   Check and coerce the schemas of recursive CTE's inputs.
   
   ## Are these changes tested?
   Yes
   
   ## Are there any user-facing changes?
   No


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to