-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-17212][SQL] TypeCoercion supports widening conversion between DateType and TimestampType #14786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Test build #64345 has finished for PR 14786 at commit
|
|
Cc @cloud-fan and @petermaxlee could you please take a look for this one? |
|
Have you checked with other databases? It looks reasonable to do this but I'd like to know how other databases deal with this case. |
|
I have only checked Hive it seems it does not handle this case. I will check others and be back soon. |
|
MySQL and PostgreSQL support this MySQL
mysql> SELECT GREATEST(CAST("1990-02-24 12:00:00" AS DATETIME), CAST("1990-02-25" AS DATE));
+-------------------------------------------------------------------------------+
| GREATEST(CAST("1990-02-24 12:00:00" AS DATETIME), CAST("1990-02-25" AS DATE)) |
+-------------------------------------------------------------------------------+
| 1990-02-25 00:00:00 |
+-------------------------------------------------------------------------------+
mysql> SELECT CAST("1990-02-24 12:00:00" AS DATETIME) UNION SELECT CAST("1990-02-24" AS DATE);
+-----------------------------------------+
| CAST("1990-02-24 12:00:00" AS DATETIME) |
+-----------------------------------------+
| 1990-02-24 12:00:00 |
| 1990-02-24 00:00:00 |
+-----------------------------------------+PostgreSQL
postgres=# SELECT GREATEST(CAST('1990-02-24 12:00:00' AS TIMESTAMP), CAST('1990-02-25' AS DATE));
greatest
---------------------
1990-02-25 00:00:00
(1 row)
postgres=# SELECT CAST('1990-02-24 12:00:00' AS TIMESTAMP) UNION SELECT CAST('1990-02-24' AS DATE);
timestamp
---------------------
1990-02-24 00:00:00
1990-02-24 12:00:00
(2 rows) |
| Some(DecimalPrecision.widerDecimalType(DecimalType.forType(t), d)) | ||
| case (_: FractionalType, _: DecimalType) | (_: DecimalType, _: FractionalType) => | ||
| Some(DoubleType) | ||
| case (_: TimestampType, _: DateType) | (_: DateType, _: TimestampType) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we put it in findTightestCommonTypeOfTwo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sure!
|
Test build #64411 has finished for PR 14786 at commit
|
| // TimestampType | ||
| widenTest(NullType, TimestampType, Some(TimestampType)) | ||
| widenTest(TimestampType, TimestampType, Some(TimestampType)) | ||
| widenTest(DateType, TimestampType, Some(TimestampType)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we only need this test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeap, fixed.
|
Test build #64419 has finished for PR 14786 at commit
|
|
thanks, merging to master! |
… for set operations ## What changes were proposed in this pull request? This PR backports #15072 Please note that the test code is a bit different with the master as #14786 was only merged into master and therefore, it does not support type-widening between `DateType` and `TimestampType`. So, both types were taken out from the test. ## How was this patch tested? Unit test in `DataFrameSuite`. Author: hyukjinkwon <[email protected]> Closes #15601 from HyukjinKwon/backport-17123.
What changes were proposed in this pull request?
Currently, type-widening does not work between
TimestampTypeandDateType.This applies to
SetOperation,Union,In,CaseWhen,Greatest,Leatest,CreateArray,CreateMap,Coalesce,NullIf,IfNull,NvlandNvl2, .This PR adds the support for widening
DateTypetoTimestampTypefor them.For a simple example,
Before
shows below:
or union as below:
shows below:
After
shows below:
or union as below:
shows below:
How was this patch tested?
Unit tests in
TypeCoercionSuite.