MaxGekk opened a new pull request #35787:
URL: https://github.com/apache/spark/pull/35787


   ### What changes were proposed in this pull request?
   In the PR, I propose to throw `SparkArithmeticException` from the datetime 
function: `timestampadd()` and from its aliases `date_add()`/`dateadd()` with 
the error class `DATETIME_OVERFLOW` in the case when internal arithmetic or 
datetime overflow occurs.  The new error classes are added to 
`error-classes.json`.
   
   ### Why are the changes needed?
   Porting the functions to new error framework should improve user experience 
with Spark SQL.
   
   Before the changes:
   ```sql
   spark-sql> select timestampadd(YEAR, 1000000, timestamp'2022-03-09 
01:02:03');
   java.lang.ArithmeticException: long overflow
        at java.lang.Math.multiplyExact(Math.java:892) ~[?:1.8.0_292]
   ```
   
   After:
   ```sql
   spark-sql> select timestampadd(YEAR, 1000000, timestamp'2022-03-09 
01:02:03');
   org.apache.spark.SparkArithmeticException: The 'timestampadd' function 
overflows the input '2022-03-08T22:02:03Z' timestamp by 1000000 YEAR.
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   Yes, but the datetime functions `timestampadd()` and its aliases 
`dateadd()`/`date_add()` haven't released yet.
   
   ### How was this patch tested?
   By running the affected test suites:
   ```
   $ build/sbt "test:testOnly *SparkThrowableSuite"
   ```
   and new test:
   ```
   $ build/sbt "test:testOnly *QueryExecutionErrorsSuite"
   ```


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