MaxGekk commented on code in PR #56810:
URL: https://github.com/apache/spark/pull/56810#discussion_r3481911342
##########
sql/api/src/main/scala/org/apache/spark/sql/types/UpCastRule.scala:
##########
@@ -36,10 +36,17 @@ private[sql] object UpCastRule {
case (from: NumericType, to: DecimalType) if to.isWiderThan(from) => true
case (from: DecimalType, to: NumericType) if from.isTighterThan(to) => true
case (f, t) if legalNumericPrecedence(f, t) => true
- case (DateType, TimestampType) => true
- case (DateType, TimestampNTZType) => true
- case (TimestampNTZType, TimestampType) => true
- case (TimestampType, TimestampNTZType) => true
+ // Widening DATE -> timestamp family (micro or nanos, LTZ or NTZ) is
lossless; the reverse
+ // (timestamp -> DATE) drops the time-of-day and is not matched here, so
it stays a non-up-cast.
+ case (DateType, t) if TimestampFamily.fractionalPrecision(t).isDefined =>
true
+ // Lossless widening within the timestamp family: target fractional-second
precision >= source.
+ // Covers micros <-> nanos and the cross-family LTZ <-> NTZ pairs
(mirroring how the micro
+ // TimestampType <-> TimestampNTZType pair is a mutual up-cast). Equal
precision is handled by
+ // the `from == to` short-circuit above; lossy narrowing falls through to
`case _ => false`.
+ case (f, t)
+ if TimestampFamily.fractionalPrecision(f).isDefined &&
+ TimestampFamily.fractionalPrecision(t).isDefined =>
+ TimestampFamily.fractionalPrecision(f).get <=
TimestampFamily.fractionalPrecision(t).get
Review Comment:
Thanks — adopted the `.exists` form in 2302117. I kept it as a guard with a
`=> true` body rather than a guardless `case (f, t) =>`, since a guardless
catch-all here would shadow the
`String`/`Null`/`Timestamp↔Long`/`Array`/`Map`/`Struct` cases just below and
return `false` for those non-timestamp pairs. Also tightened the adjacent
comment about equal-precision handling.
--
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]