cloud-fan commented on code in PR #40693:
URL: https://github.com/apache/spark/pull/40693#discussion_r1162208044


##########
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 is really ugly... I'm wondering if we should just remove 
`PhysicalNumericType`, and make `numeric` a field in the top level 
`PhysicalDataType`, If a type doesn't support numeric, it should throw an 
exception.
   
   Then here we can just write
   ```
   lazy val numeric = PhysicalType.numeric(from)
   from match {
     ...
   }
   ```



-- 
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]

Reply via email to