Uh oh!
There was an error while loading. Please reload this page.
[SPARK-28420][SQL] Support the INTERVAL type in date_part() - #25981
[SPARK-28420][SQL] Support the INTERVAL type in date_part()#25981MaxGekk wants to merge 43 commits into
INTERVAL type in date_part()#25981Conversation
SparkQA
commented
Oct 12, 2019
Test build #111946 has finished for PR 25981 at commit
|
SparkQA
commented
Oct 12, 2019
Test build #111967 has finished for PR 25981 at commit
|
MaxGekk
commented
Oct 13, 2019
@cloud-fan@dongjoon-hyun Please, review this PR one more time. |
MaxGekk
commented
Oct 15, 2019
What else can I do here? |
cloud-fan
commented
Oct 17, 2019
There is one question not addressed: https://github.com/apache/spark/pull/25981/files#r332578044 What's the motivation of this PR? If it's to add a new feature, internal consistency is very important. If it's for pgsql compatibility, let's follow pgsql completely and enable it only when dialect=pgsql. |
MaxGekk
commented
Oct 17, 2019
Github didn't allow me to put my answer under @srowen question, and I had to continue discussion on the main page: #25981 (comment)
The motivation is still the same as I wrote in the PR description: To maintain feature parity with PostgreSQL (https://www.postgresql.org/docs/11/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT)
The |
MaxGekk
commented
Oct 17, 2019
@cloud-fan Should I revert the last 2 commits? |
cloud-fan
commented
Oct 17, 2019
Before I look into the code, let me ask a few high-level questions. I'm ok with exposing the |
MaxGekk
commented
Oct 17, 2019
Here are examples for units smaller than second in PostgreSQL (my implementation behaves the same): maxim=# SELECT date_part('milliseconds', interval '10 minutes 30 seconds 1 milliseconds 1 microseconds');
date_part
-----------30001.001
(1 row)
maxim=# SELECT date_part('microseconds', interval '10 minutes 30 seconds 1 milliseconds 1 microseconds');
date_part
-----------30001001
(1 row)Similar for timestamps: maxim=# SELECT date_part('milliseconds', timestamp'2019-10-17 11:12:30.001001');
date_part
-----------30001.001
(1 row)
maxim=# SELECT date_part('microseconds', timestamp'2019-10-17 11:12:30.001001');
date_part
-----------30001001
(1 row) |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| case class ExtractIntervalMilliseconds(child: Expression) | ||
| extends ExtractIntervalPart(child, DecimalType(8, 3), getMilliseconds, "getMilliseconds") | ||
| case class ExtractIntervalMicroseconds(child: Expression) |
There was a problem hiding this comment.
not related to this PR, but we can apply the same naming policy to the related date/timestamp functions.
SparkQA
commented
Oct 18, 2019
Test build #112260 has finished for PR 25981 at commit
|
SparkQA
commented
Oct 18, 2019
Test build #112262 has finished for PR 25981 at commit
|
cloud-fan
commented
Oct 18, 2019
thanks, merging to master! |
MaxGekk
commented
Oct 18, 2019
@cloud-fan Thank you. |
What changes were proposed in this pull request?
The
date_part()function can accept thesourceparameter of theINTERVALtype (CalendarIntervalType). The following values of thefieldparameter are supported:"MILLENNIUM"("MILLENNIA","MIL","MILS") - number of millenniums in the given interval. It isYEAR / 1000."CENTURY"("CENTURIES","C","CENT") - number of centuries in the interval calculated asYEAR / 100."DECADE"("DECADES","DEC","DECS") - decades in theYEARpart of the interval calculated asYEAR / 10."YEAR"("Y","YEARS","YR","YRS") - years in a values ofCalendarIntervalType. It isMONTHS / 12."QUARTER"("QTR") - a quarter of year calculated asMONTHS / 3 + 1"MONTH"("MON","MONS","MONTHS") - the months part of the interval calculated asCalendarInterval.months % 12"DAY"("D","DAYS") - total number of days inCalendarInterval.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 thesecond,millisecondandmicrosecondparts 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:
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?
IntervalExpressionsSuitedate_part.sql