MaxGekk opened a new pull request #26112: [SPARK-29364][SQL] Return an interval 
from date subtract according to SQL standard
URL: https://github.com/apache/spark/pull/26112
 
 
   ### What changes were proposed in this pull request?
   Proposed new expression `SubtractDates` which is used in `date1` - `date2`. 
It has the `INTERVAL` type, and returns the interval from `date1` (inclusive) 
and `date2` (exclusive). For example:
   ```sql
   > select date'tomorrow' - date'yesterday';
   interval 2 days
   ```
   
   Closes #26034
   
   ### Why are the changes needed?
   - To conform the SQL standard which states the result type of `date operand 
1` - `date operand 2` must be the interval type.
   - Improve Spark SQL UX and allow mixing date and timestamp in subtractions. 
For example: `select timestamp'now' + (date'2019-10-01' - date'2019-09-15')`
   
   ### Does this PR introduce any user-facing change?
   Before the query below returns number of days:
   ```sql
   spark-sql> select date'2019-10-05' - date'2018-09-01';
   399
   ```
   After it returns an interval:
   ```sql
   spark-sql> select date'2019-10-05' - date'2018-09-01';
   interval 1 years 1 months 4 days
   ```
   
   ### How was this patch tested?
   - by new tests in `DateExpressionsSuite`.
   - by existing tests in `date.sql`
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to