diff options
author | hyukjinkwon <gurwls223@gmail.com> | 2016-08-26 08:58:43 +0800 |
---|---|---|
committer | Wenchen Fan <wenchen@databricks.com> | 2016-08-26 08:58:43 +0800 |
commit | b964a172a8c075486189cc9be09a51b8446f0da4 (patch) | |
tree | b09f17e3da28cd5c8fde906d99b7b0da12bd7cea /sbin/spark-config.sh | |
parent | d96d1515638da20b594f7bfe3cfdb50088f25a04 (diff) | |
download | spark-b964a172a8c075486189cc9be09a51b8446f0da4.tar.gz spark-b964a172a8c075486189cc9be09a51b8446f0da4.tar.bz2 spark-b964a172a8c075486189cc9be09a51b8446f0da4.zip |
[SPARK-17212][SQL] TypeCoercion supports widening conversion between DateType and TimestampType
## What changes were proposed in this pull request?
Currently, type-widening does not work between `TimestampType` and `DateType`.
This applies to `SetOperation`, `Union`, `In`, `CaseWhen`, `Greatest`, `Leatest`, `CreateArray`, `CreateMap`, `Coalesce`, `NullIf`, `IfNull`, `Nvl` and `Nvl2`, .
This PR adds the support for widening `DateType` to `TimestampType` for them.
For a simple example,
**Before**
```scala
Seq(Tuple2(new Timestamp(0), new Date(0))).toDF("a", "b").selectExpr("greatest(a, b)").show()
```
shows below:
```
cannot resolve 'greatest(`a`, `b`)' due to data type mismatch: The expressions should all have the same type, got GREATEST(timestamp, date)
```
or union as below:
```scala
val a = Seq(Tuple1(new Timestamp(0))).toDF()
val b = Seq(Tuple1(new Date(0))).toDF()
a.union(b).show()
```
shows below:
```
Union can only be performed on tables with the compatible column types. DateType <> TimestampType at the first column of the second table;
```
**After**
```scala
Seq(Tuple2(new Timestamp(0), new Date(0))).toDF("a", "b").selectExpr("greatest(a, b)").show()
```
shows below:
```
+----------------------------------------------------+
|greatest(CAST(a AS TIMESTAMP), CAST(b AS TIMESTAMP))|
+----------------------------------------------------+
| 1969-12-31 16:00:...|
+----------------------------------------------------+
```
or union as below:
```scala
val a = Seq(Tuple1(new Timestamp(0))).toDF()
val b = Seq(Tuple1(new Date(0))).toDF()
a.union(b).show()
```
shows below:
```
+--------------------+
| _1|
+--------------------+
|1969-12-31 16:00:...|
|1969-12-31 00:00:...|
+--------------------+
```
## How was this patch tested?
Unit tests in `TypeCoercionSuite`.
Author: hyukjinkwon <gurwls223@gmail.com>
Author: HyukjinKwon <gurwls223@gmail.com>
Closes #14786 from HyukjinKwon/SPARK-17212.
Diffstat (limited to 'sbin/spark-config.sh')
0 files changed, 0 insertions, 0 deletions