goutamadwant opened a new pull request, #25956:
URL: https://github.com/apache/datafusion/pull/25956

   ## Which issue does this PR close?
   
   - Closes #25893.
   
   ## Rationale for this change
   
   A recursive CTE currently casts each recursive column to the non-recursive 
term's type, even when that discards information. A fractional increment can 
therefore become the same integer on every iteration, returning incorrect rows 
or preventing termination. The query should fail during planning and explain 
how to choose the intended output type.
   
   ## What changes are included in this PR?
   
   - Validate each recursive column before the existing schema coercion, with 
an error that identifies the CTE, column, both types, and the need to cast the 
non-recursive term.
   - Preserve the integer-to-integer behavior added for #9794 and known 
lossless scalar widenings. Reject implicit casts that can discard numeric 
precision or narrow decimal range or scale.
   - Require matching compound types rather than inferring that nested casts 
are lossless; users can cast the non-recursive term to the intended compound 
type explicitly.
   - Keep the check in recursive-query planning, leaving the shared 
schema-coercion helper and execution path unchanged.
   
   ## What is the testing strategy for this PR?
   
   - Added `cte.slt` regressions for float/decimal-to-integer coercion, 
integer-to-float precision loss above 2^53, float-to-decimal rounding, nested 
structs, cross-category coercion, and decimal range saturation. The error cases 
use `EXPLAIN` so they cannot run indefinitely.
   - Added positive cases for an explicitly widened seed and safe 
decimal/date/string/binary widening; the existing integer-to-integer recursion 
test still passes. The error cases were verified to fail without the relevant 
guard and pass with it.
   - Ran `cargo fmt --all`, `cargo clippy --all-targets --all-features -- -D 
warnings`, the focused `cte.slt` suite, and the extended workspace test command 
from `AGENTS.md`.
   
   ## Are there any user-facing changes?
   
   Yes. Recursive CTEs with unsafe implicit type coercion or mismatched 
compound types now fail at planning time with a hint to cast the non-recursive 
term to the intended type. No public API changes.


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to