MaxGekk opened a new pull request #25708: [SPARK-28141][SQL] Support special 
date values
URL: https://github.com/apache/spark/pull/25708
 
 
   ### What changes were proposed in this pull request?
   
   Supported special string values for `DATE` type. They are simply notational 
shorthands that will be converted to ordinary date values when read. The 
following string values are supported:
   - `epoch` - `1970-01-01`
   - `now` - the date of running the current query
   - `today` - the current date. The same as `now`.
   - `yesterday` - the current date -1
   - `tomorrow` - the current date + 1
   
   For example:
   ```sql
   spark-sql> SELECT date 'tomorrow' - date 'yesterday';
   2
   ```
   
   ### Why are the changes needed?
   
   To maintain feature parity with PostgreSQL, see [8.5.1.4. Special 
Values](https://www.postgresql.org/docs/12/datatype-datetime.html)
   
   
   ### Does this PR introduce any user-facing change?
   
   Previously, the parser fails on the special values with the error:
   ```sql
   spark-sql> select date 'today';
   Error in query: 
   Cannot parse the DATE value: today(line 1, pos 7)
   ```
   After the changes, the special values are converted to appropriate dates:
   ```sql
   spark-sql> select date 'today';
   2019-09-06
   ```
   
   ### How was this patch tested?
   - Added tests to `DateFormatterSuite` to check parsing special values from 
regular strings.
   - Tests in `DateTimeUtilsSuite` check parsing those values from `UTF8String`
   - Uncommented 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