SEPURI-SAI-KRISHNA commented on code in PR #60134: URL: https://github.com/apache/spark/pull/60134#discussion_r4579502419
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeExpressions.scala: ########## @@ -3779,11 +3779,12 @@ case class DateDiff(endDate: Expression, startDate: Expression) override def dataType: DataType = IntegerType Review Comment: Thanks @stevomitric, good catch, confirmed. Under `LEGACY`, `toSQLValue(_, DateType)` goes through `LegacyDateFormatter.format`, and `RebaseDateTime.localRebaseGregorianToJulianDays` throws `ArithmeticException: integer overflow` from `Math.toIntExact` for the dates within about 44,500 days of the minimum DATE. So `datediff(date_from_unix_date(-2147483648), date_from_unix_date(1))` failed with a raw `ArithmeticException`, and so did `date_from_unix_date(-2147483648) - date_from_unix_date(0)`, which reaches the same error. The `trunc` overflow error from SPARK-60929 has the same problem, since `trunc` overflows only at the minimum DATE, e.g. `trunc(date_from_unix_date(-2147483648), 'QUARTER')` under `LEGACY`. Fixed in 49e0d76ede1: a private `QueryExecutionErrors.toSQLDate` formats with `DefaultDateFormatter`, in the proleptic Gregorian calendar of DATE values, whatever the policy. `subtractDatesOverflowError` and the `next_day` / `last_day` / `trunc` overflow errors use it. The text is unchanged under `CORRECTED` and `EXCEPTION`; under `LEGACY` the maximum DATE now prints as `+5881580-07-11`, as it does under the other policies. Tests: a new `DateExpressionsSuite` case runs the `datediff` overflow at both ends of the DATE range, and the date subtraction and `trunc` overflows at the minimum DATE, under all three policies (without the change it fails under `LEGACY` with the raw `ArithmeticException`). `date.sql` has two new queries that overflow at the minimum DATE, and `datetime-legacy.sql` runs them under `LEGACY`. I also merged master to resolve the migration-guide conflict with SPARK-60929. -- 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]
