Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/21586#discussion_r196283540
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
---
@@ -116,22 +116,23 @@ object Cast {
}
/**
- * Return true iff we may truncate during casting `from` type to `to`
type. e.g. long -> int,
- * timestamp -> date.
+ * Returns true iff we can safely cast the `from` type to `to` type
without any truncating or
+ * precision lose, e.g. int -> long, date -> timestamp.
*/
- def mayTruncate(from: DataType, to: DataType): Boolean = (from, to)
match {
- case (from: NumericType, to: DecimalType) if !to.isWiderThan(from) =>
true
- case (from: DecimalType, to: NumericType) if !from.isTighterThan(to)
=> true
- case (from, to) if illegalNumericPrecedence(from, to) => true
- case (TimestampType, DateType) => true
- case (StringType, to: NumericType) => true
+ def canSafeCast(from: DataType, to: DataType): Boolean = (from, to)
match {
+ case _ if from == to => true
--- End diff --
Seems `nullable` of `StructField` can affect the casting decision?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]