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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/timeExpressions.scala:
##########
@@ -34,11 +34,83 @@ import org.apache.spark.sql.catalyst.util.DateTimeUtils
 import org.apache.spark.sql.catalyst.util.TimeFormatter
 import org.apache.spark.sql.catalyst.util.TypeUtils.ordinalNumber
 import org.apache.spark.sql.errors.{QueryCompilationErrors, 
QueryExecutionErrors}
+import org.apache.spark.sql.internal.SQLConf
 import org.apache.spark.sql.internal.types.StringTypeWithCollation
-import org.apache.spark.sql.types.{AbstractDataType, AnyTimeType, ByteType, 
DataType, DayTimeIntervalType, Decimal, DecimalType, DoubleType, FloatType, 
IntegerType, IntegralType, LongType, NumericType, ObjectType, TimeType}
+import org.apache.spark.sql.types.{AbstractDataType, AnyTimeType, ByteType, 
DataType, DayTimeIntervalType, DecimalType, IntegerType, IntegralType, 
LongType, NumericType, ObjectType, TimeType}
 import org.apache.spark.sql.types.DayTimeIntervalType.{HOUR, SECOND}
 import org.apache.spark.unsafe.types.UTF8String
 
+/**
+ * Helper trait for TIME conversion expressions with consistent error handling.
+ */
+trait TimeConversionErrorHandling {
+  def failOnError: Boolean
+
+  /** Wraps evaluation with error handling (throws in ANSI mode, null 
otherwise). */
+  protected def evalWithErrorHandling[T](f: => T): Any = {
+    try {
+      f
+    } catch {
+      case e: DateTimeException if failOnError =>
+        throw QueryExecutionErrors.ansiDateTimeArgumentOutOfRange(e)
+      case e: ArithmeticException if failOnError =>
+        throw QueryExecutionErrors.ansiDateTimeArgumentOutOfRange(
+          new DateTimeException(s"Overflow in TIME conversion: 
${e.getMessage}"))

Review Comment:
   can we pass `e` directly?



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