kumarUjjawal commented on code in PR #25956:
URL: https://github.com/apache/datafusion/pull/25956#discussion_r4163107479
##########
datafusion/expr/src/logical_plan/builder.rs:
##########
@@ -88,6 +90,93 @@ impl LogicalPlanBuilderOptions {
}
}
+fn recursive_type_can_be_coerced(from: &DataType, into: &DataType) -> bool {
+ if from == into || *from == DataType::Null {
+ return true;
+ }
+ // Preserve the integer coercion supported by recursive queries since
#9794.
+ if from.is_integer() && into.is_integer() {
+ return true;
+ }
+ if matches!(
+ (from, into),
+ (DataType::Date32, DataType::Date64)
+ | (DataType::Utf8, DataType::LargeUtf8 | DataType::Utf8View)
+ | (DataType::LargeUtf8, DataType::Utf8View)
+ | (
+ DataType::Binary,
+ DataType::LargeBinary | DataType::BinaryView
+ )
+ | (DataType::LargeBinary, DataType::BinaryView)
+ | (
+ DataType::FixedSizeBinary(_),
+ DataType::Binary | DataType::BinaryView
+ )
+ ) {
+ return true;
+ }
+ // Compound types and changes of type category need an explicit seed type.
+ // UNION's common-type rules can hide lossy casts within nested fields.
+ if !from.is_numeric() || !into.is_numeric() {
+ return false;
+ }
+ if type_union_coercion(into, from).as_ref() != Some(into) {
+ return false;
+ }
Review Comment:
**Medium ยท Apply decimal range checks before the UNION-type gate**
For an `Int64` recursive column and a `DECIMAL(19,0)` seed, this gate
rejects a lossless conversion: `type_union_coercion` represents signed and
unsigned 64-bit integers as `Decimal128(20,0)`, although every signed `Int64`
fits in 19 digits. Consequently, `WITH RECURSIVE t AS (SELECT 1::DECIMAL(19,0)
AS a UNION ALL SELECT 2::BIGINT FROM t WHERE a < 2) SELECT * FROM t` now fails
planning. The more accurate signed-integer range check below is never reached.
Handle decimal destinations with that range/scale check before requiring
equality with UNION's common type.
--
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]