SEPURI-SAI-KRISHNA commented on code in PR #59135:
URL: https://github.com/apache/spark/pull/59135#discussion_r4651752256


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/errors/QueryExecutionErrors.scala:
##########
@@ -2925,6 +2926,35 @@ private[sql] object QueryExecutionErrors extends 
QueryErrorsBase with ExecutionE
       summary = "")
   }
 
+  // A DATE as a SQL literal in the proleptic Gregorian calendar of DATE 
values, whatever
+  // `spark.sql.legacy.timeParserPolicy` is. Under LEGACY, `toSQLValue(_, 
DateType)` formats with
+  // the legacy formatter, whose rebasing to the Julian calendar overflows for 
the dates within
+  // about 44,500 days of the minimum DATE, so building the error would throw 
instead.
+  private def toSQLDate(days: Int): String = {
+    val formatter = new DefaultDateFormatter(
+      DateFormatter.defaultLocale, 
LegacyDateFormats.LENIENT_SIMPLE_DATE_FORMAT, isParsing = false)
+    s"DATE '${formatter.format(days)}'"
+  }
+
+  def dateAddDaysOverflowError(days: Int, numDays: Int): ArithmeticException = 
{

Review Comment:
   Done. `DateAdd` and `DateSub` now pass their query context to the error, in 
both eval and codegen.
   
   With ANSI off, `d + 1` is first resolved to an `Add`, which has no context, 
and `copyTagsFrom` copied that empty context onto the `DateAdd` that replaces 
it. A small `DateArithmeticQueryContext` trait keeps the expression's own 
context in that case.
   
   The new test in `DateFunctionsSuite` covers `date_add`, `d - 1` and `d + 
INTERVAL '1' DAY` in SQL and `date_add` in the DataFrame API, with ANSI on and 
off. `RANGE` frame bounds are built at evaluation time, so their context is 
empty.
   



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