Chao Gao created SPARK-39352: -------------------------------- Summary: There are problems in canUpCast function Key: SPARK-39352 URL: https://issues.apache.org/jira/browse/SPARK-39352 Project: Spark Issue Type: Bug Components: Spark Core Affects Versions: 3.2.1 Reporter: Chao Gao
Spark's canUpCast means one value can be cast to another type without the loss of precision. But actually long type can not be cast to float/double {code:java} def canUpCast(from: DataType, to: DataType): Boolean = (from, to) match { case _ if from == to => true 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 (_: AtomicType, StringType) => true case (_: CalendarIntervalType, StringType) => true case (NullType, _) => true ... {code} {code:java} private def legalNumericPrecedence(from: DataType, to: DataType): Boolean = { val fromPrecedence = TypeCoercion.numericPrecedence.indexOf(from) val toPrecedence = TypeCoercion.numericPrecedence.indexOf(to) fromPrecedence >= 0 && fromPrecedence < toPrecedence } {code} {code:java} val numericPrecedence = IndexedSeq( ByteType, ShortType, IntegerType, LongType, FloatType, DoubleType) {code} -- This message was sent by Atlassian Jira (v8.20.7#820007) --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@spark.apache.org For additional commands, e-mail: issues-h...@spark.apache.org