amaliujia commented on code in PR #40693: URL: https://github.com/apache/spark/pull/40693#discussion_r1162212156
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala: ########## @@ -902,152 +903,191 @@ case class Cast( } // LongConverter - private[this] def castToLong(from: DataType): Any => Any = from match { - case StringType if ansiEnabled => - buildCast[UTF8String](_, v => UTF8StringUtils.toLongExact(v, getContextOrNull())) - case StringType => - val result = new LongWrapper() - buildCast[UTF8String](_, s => if (s.toLong(result)) result.value else null) - case BooleanType => - buildCast[Boolean](_, b => if (b) 1L else 0L) - case DateType => - buildCast[Int](_, d => null) - case TimestampType => - buildCast[Long](_, t => timestampToLong(t)) - case x: NumericType if ansiEnabled => - b => x.exactNumeric.asInstanceOf[Numeric[Any]].toLong(b) - case x: NumericType => - b => x.numeric.asInstanceOf[Numeric[Any]].toLong(b) - case x: DayTimeIntervalType => - buildCast[Long](_, i => dayTimeIntervalToLong(i, x.startField, x.endField)) - case x: YearMonthIntervalType => - buildCast[Int](_, i => yearMonthIntervalToInt(i, x.startField, x.endField).toLong) + private[this] def castToLong(from: DataType): Any => Any = { + var exactNumeric: Numeric[Any] = null + var numeric: Numeric[Any] = null Review Comment: This won't work because there is a `PhysicalDataType(dt).asInstanceOf[PhysicalNumericType]` thus the code will break whenever the type is not numeric type. We will see exception like `xxx cannot be cast to PhysicalNumericType`. -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org