eecef75350
### What changes were proposed in this pull request? Added new expression `TimestampDiff` for timestamp subtractions. It accepts 2 timestamp expressions and returns another one of the `CalendarIntervalType`. While creating an instance of `CalendarInterval`, it initializes only the microsecond field by difference of the given timestamps in microseconds, and set the `months` field to zero. Also I added an rule for conversion `Subtract` to `TimestampDiff`, and enabled already ported test queries in `postgreSQL/timestamp.sql`. ### Why are the changes needed? To maintain feature parity with PostgreSQL which allows to get timestamp difference: ```sql # select timestamp'today' - timestamp'yesterday'; ?column? ---------- 1 day (1 row) ``` ### Does this PR introduce any user-facing change? Yes, previously users got the following error from timestamp subtraction: ```sql spark-sql> select timestamp'today' - timestamp'yesterday'; Error in query: cannot resolve '(TIMESTAMP('2019-10-04 00:00:00') - TIMESTAMP('2019-10-03 00:00:00'))' due to data type mismatch: '(TIMESTAMP('2019-10-04 00:00:00') - TIMESTAMP('2019-10-03 00:00:00'))' requires (numeric or interval) type, not timestamp; line 1 pos 7; 'Project [unresolvedalias((1570136400000000 - 1570050000000000), None)] +- OneRowRelation ``` after the changes they should get an interval: ```sql spark-sql> select timestamp'today' - timestamp'yesterday'; interval 1 days ``` ### How was this patch tested? - Added tests for `TimestampDiff` to `DateExpressionsSuite` - By new test in `TypeCoercionSuite`. - Enabled tests in `postgreSQL/timestamp.sql`. Closes #26022 from MaxGekk/timestamp-diff. Authored-by: Maxim Gekk <max.gekk@gmail.com> Signed-off-by: Dongjoon Hyun <dhyun@apple.com> |
||
---|---|---|
.. | ||
benchmarks | ||
src | ||
pom.xml |