{"action":"created","issue":{"url":"https://api.github.com/repos/apache/spark/issues/14786","repository_url":"https://api.github.com/repos/apache/spark","labels_url":"https://api.github.com/repos/apache/spark/issues/14786/labels{/name}","comments_url":"https://api.github.com/repos/apache/spark/issues/14786/comments","events_url":"https://api.github.com/repos/apache/spark/issues/14786/events","html_url":"https://github.com/apache/spark/pull/14786","id":172922096,"number":14786,"title":"[SPARK-17212][SQL] TypeCoercion supports widening conversion between DateType and TimestampType","user":{"login":"HyukjinKwon","id":6477701,"avatar_url":"https://avatars.githubusercontent.com/u/6477701?v=3","gravatar_id":"","url":"https://api.github.com/users/HyukjinKwon","html_url":"https://github.com/HyukjinKwon","followers_url":"https://api.github.com/users/HyukjinKwon/followers","following_url":"https://api.github.com/users/HyukjinKwon/following{/other_user}","gists_url":"https://api.github.com/users/HyukjinKwon/gists{/gist_id}","starred_url":"https://api.github.com/users/HyukjinKwon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HyukjinKwon/subscriptions","organizations_url":"https://api.github.com/users/HyukjinKwon/orgs","repos_url":"https://api.github.com/users/HyukjinKwon/repos","events_url":"https://api.github.com/users/HyukjinKwon/events{/privacy}","received_events_url":"https://api.github.com/users/HyukjinKwon/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2016-08-24T10:55:06Z","updated_at":"2016-08-26T00:59:50Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/14786","html_url":"https://github.com/apache/spark/pull/14786","diff_url":"https://github.com/apache/spark/pull/14786.diff","patch_url":"https://github.com/apache/spark/pull/14786.patch"},"body":"## What changes were proposed in this pull request?\r\n\r\nCurrently, type-widening does not work between `TimestampType` and `DateType`.\r\n\r\nThis applies to `SetOperation`, `Union`, `In`, `CaseWhen`, `Greatest`,  `Leatest`, `CreateArray`, `CreateMap`, `Coalesce`, `NullIf`, `IfNull`, `Nvl` and `Nvl2`, .\r\n\r\nThis PR adds the support for widening `DateType` to `TimestampType` for them.\r\n\r\nFor a simple example, \r\n\r\n**Before**\r\n\r\n```scala\r\nSeq(Tuple2(new Timestamp(0), new Date(0))).toDF(\"a\", \"b\").selectExpr(\"greatest(a, b)\").show()\r\n```\r\n\r\nshows below:\r\n\r\n```\r\ncannot resolve 'greatest(`a`, `b`)' due to data type mismatch: The expressions should all have the same type, got GREATEST(timestamp, date)\r\n```\r\n\r\nor union as below:\r\n\r\n```scala\r\nval a = Seq(Tuple1(new Timestamp(0))).toDF()\r\nval b = Seq(Tuple1(new Date(0))).toDF()\r\na.union(b).show()\r\n```\r\n\r\nshows below:\r\n\r\n```\r\nUnion can only be performed on tables with the compatible column types. DateType <> TimestampType at the first column of the second table;\r\n```\r\n\r\n**After**\r\n\r\n```scala\r\nSeq(Tuple2(new Timestamp(0), new Date(0))).toDF(\"a\", \"b\").selectExpr(\"greatest(a, b)\").show()\r\n```\r\n\r\nshows below:\r\n\r\n```\r\n+----------------------------------------------------+\r\n|greatest(CAST(a AS TIMESTAMP), CAST(b AS TIMESTAMP))|\r\n+----------------------------------------------------+\r\n|                                1969-12-31 16:00:...|\r\n+----------------------------------------------------+\r\n```\r\n\r\nor union as below:\r\n\r\n```scala\r\nval a = Seq(Tuple1(new Timestamp(0))).toDF()\r\nval b = Seq(Tuple1(new Date(0))).toDF()\r\na.union(b).show()\r\n```\r\n\r\nshows below:\r\n\r\n```\r\n+--------------------+\r\n|                  _1|\r\n+--------------------+\r\n|1969-12-31 16:00:...|\r\n|1969-12-31 00:00:...|\r\n+--------------------+\r\n```\r\n\r\n\r\n## How was this patch tested?\r\n\r\nUnit tests in `TypeCoercionSuite`."},"comment":{"url":"https://api.github.com/repos/apache/spark/issues/comments/242591202","html_url":"https://github.com/apache/spark/pull/14786#issuecomment-242591202","issue_url":"https://api.github.com/repos/apache/spark/issues/14786","id":242591202,"user":{"login":"cloud-fan","id":3182036,"avatar_url":"https://avatars.githubusercontent.com/u/3182036?v=3","gravatar_id":"","url":"https://api.github.com/users/cloud-fan","html_url":"https://github.com/cloud-fan","followers_url":"https://api.github.com/users/cloud-fan/followers","following_url":"https://api.github.com/users/cloud-fan/following{/other_user}","gists_url":"https://api.github.com/users/cloud-fan/gists{/gist_id}","starred_url":"https://api.github.com/users/cloud-fan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloud-fan/subscriptions","organizations_url":"https://api.github.com/users/cloud-fan/orgs","repos_url":"https://api.github.com/users/cloud-fan/repos","events_url":"https://api.github.com/users/cloud-fan/events{/privacy}","received_events_url":"https://api.github.com/users/cloud-fan/received_events","type":"User","site_admin":false},"created_at":"2016-08-26T00:59:50Z","updated_at":"2016-08-26T00:59:50Z","body":"thanks, merging to master!"}}
{"actor":{"display_login":"cloud-fan"}}