MaxGekk opened a new pull request #26079: [SPARK-29369][SQL] Support string 
intervals without the `interval` prefix
URL: https://github.com/apache/spark/pull/26079
 
 
   ### What changes were proposed in this pull request?
   In the PR, I propose to move interval parsing to 
`CalendarInterval.fromCaseInsensitiveString()` which throws an 
`IllegalArgumentException` for invalid strings, and reuse it from 
`CalendarInterval.fromString()`. The former one handles 
`IllegalArgumentException` only and returns `NULL` for invalid interval 
strings. This will allow to support interval strings without the `interval` 
prefix in casting strings to intervals and in interval type constructor.
   For example:
   ```sql
   spark-sql> select cast('1 year 10 days' as interval);
   interval 1 years 1 weeks 3 days
   spark-sql> SELECT INTERVAL '1 YEAR 10 DAYS';
   interval 1 years 1 weeks 3 days
   ```
   
   ### Why are the changes needed?
   To maintain feature parity with PostgreSQL which supports interval strings 
without prefix:
   ```sql
   # select interval '2 months 1 microsecond';
           interval        
   ------------------------
    2 mons 00:00:00.000001
   ```
   
   ### Does this PR introduce any user-facing change?
   Yes, previously parsing interval strings without `interval` gives `NULL`:
   ```sql
   spark-sql> select interval '2 months 1 microsecond';
   NULL
   ```
   After:
   ```sql
   spark-sql> select interval '2 months 1 microsecond';
   interval 2 months 1 microseconds
   ```
   
   ### How was this patch tested?
   - Added new tests to `CalendarIntervalSuite.java`
   - A test for casting strings to intervals in `CastSuite`
   - Test for interval type constructor from strings in `ExpressionParserSuite`
   

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to