wangyum commented on code in PR #40790:
URL: https://github.com/apache/spark/pull/40790#discussion_r1167672641
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala:
##########
@@ -396,6 +396,22 @@ object Cast extends QueryErrorsBase {
case (_, to: DecimalType) if !canNullSafeCastToDecimal(from, to) => true
case (_: FractionalType, _: IntegralType) => true // NaN, infinity
+
+ case (_: ArrayType, _: ArrayType) => false
+ case (_: MapType, _: MapType) => false
+ case (_: StructType, _: StructType) => false
+ case (_: ArrayType | _: MapType | _: StructType, _) => true
+
+ case (DateType | TimestampType, TimestampNTZType) => false
+ case (_, TimestampNTZType) => true
+ case (TimestampNTZType, DateType | TimestampType) => false
+ case (TimestampNTZType, _) => true
+
+ case (_: IntegralType | _: DecimalType, _: AnsiIntervalType) => false
+ case (_, _: AnsiIntervalType) => true
+ case (_: AnsiIntervalType, _: IntegralType | _: DecimalType) => false
+ case (_: AnsiIntervalType, _) => true
+
Review Comment:
Could you add a test to test all types? For example:
```scala
TypeCoercionSuite.allTypes.foreach { dt1 =>
TypeCoercionSuite.allTypes.foreach { dt2 =>
Cast.forceNullable(dt1, dt2)
...
```
--
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]