MaxGekk opened a new pull request #25981: [SPARK-28420][SQL] Support the 
`INTERVAL` type in `date_part()`
URL: https://github.com/apache/spark/pull/25981
 
 
   ### What changes were proposed in this pull request?
   The `date_part()` function can accept the `source` parameter of the 
`INTERVAL` type (`CalendarIntervalType`). The following values of the `field` 
parameter are supported:
   - `"MILLENNIUM"` (`"MILLENNIA"`, `"MIL"`, `"MILS"`) - number of millenniums 
in the given interval. It is `YEAR / 1000`.
   - `"CENTURY"` (`"CENTURIES"`, `"C"`, `"CENT"`) - number of centuries in the 
interval calculated as `YEAR / 100`.
   - `"DECADE"` (`"DECADES"`, `"DEC"`, `"DECS"`) - decades in the `YEAR` part 
of the interval calculated as `YEAR / 10`.
   - `"YEAR"` (`"Y"`, `"YEARS"`, `"YR"`, `"YRS"`) - years in a values of 
`CalendarIntervalType`. It is `MONTHS / 12`.
   - `"QUARTER"` (`"QTR"`) - a quarter of year calculated as `MONTHS / 3 + 1` 
   - `"MONTH"` (`"MON"`, `"MONS"`, `"MONTHS"`) - the months part of the 
interval calculated as `CalendarInterval.months % 12`
   - `"DAY"` (`"D"`, `"DAYS"`) - total number of days in 
`CalendarInterval.microseconds` 
   - `"HOUR"` (`"H"`, `"HOURS"`, `"HR"`, `"HRS"`) - the hour part of the 
interval.
   - `"MINUTE"` (`"M"`, `"MIN"`, `"MINS"`, `"MINUTES"`) - the minute part of 
the interval.
   - `"SECOND"` (`"S"`, `"SEC"`, `"SECONDS"`, `"SECS"`) - the seconds part with 
fractional microsecond part.  
   - `"MILLISECONDS"` (`"MSEC"`, `"MSECS"`, `"MILLISECON"`, `"MSECONDS"`, 
`"MS"`) - the millisecond part of the interval with fractional microsecond part.
   - `"MICROSECONDS"` (`"USEC"`, `"USECS"`, `"USECONDS"`, `"MICROSECON"`, 
`"US"`) - the total number of microseconds in the `second`, `millisecond` and 
`microsecond` parts of the given interval.
   - `"EPOCH"` - the total number of seconds in the interval including the 
fractional part with microsecond precision. Here we assume 365.25 days per year 
(leap year every four years).
   
   For example:
   ```sql
   > SELECT date_part('days', interval 1 year 10 months 5 days);
    5
   > SELECT date_part('seconds', interval 30 seconds 1 milliseconds 1 
microseconds);
    30.001001
   ```
   
   ### Why are the changes needed?
   To maintain feature parity with PostgreSQL 
(https://www.postgresql.org/docs/11/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT)
   
   ### Does this PR introduce any user-facing change?
   No
   
   ### How was this patch tested?
   - Added new test suite `IntervalExpressionsSuite`
   - Add new test cases to `date_part.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