{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/93712892","pull_request_review_id":14071777,"id":93712892,"diff_hunk":"@@ -135,6 +167,15 @@ case class Cast(child: Expression, dataType: DataType) extends UnaryExpression w\n \n   override def nullable: Boolean = Cast.forceNullable(child.dataType, dataType) || child.nullable\n \n+  override def timeZoneResolved: Boolean =","path":"sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala","position":56,"original_position":56,"commit_id":"4b6900cf6d182d87a545d736d320c6229fb8251d","original_commit_id":"4b6900cf6d182d87a545d736d320c6229fb8251d","user":{"login":"hvanhovell","id":9616802,"avatar_url":"https://avatars.githubusercontent.com/u/9616802?v=3","gravatar_id":"","url":"https://api.github.com/users/hvanhovell","html_url":"https://github.com/hvanhovell","followers_url":"https://api.github.com/users/hvanhovell/followers","following_url":"https://api.github.com/users/hvanhovell/following{/other_user}","gists_url":"https://api.github.com/users/hvanhovell/gists{/gist_id}","starred_url":"https://api.github.com/users/hvanhovell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hvanhovell/subscriptions","organizations_url":"https://api.github.com/users/hvanhovell/orgs","repos_url":"https://api.github.com/users/hvanhovell/repos","events_url":"https://api.github.com/users/hvanhovell/events{/privacy}","received_events_url":"https://api.github.com/users/hvanhovell/received_events","type":"User","site_admin":false},"body":"This a mental note. A timezone is resolved when:\r\n- We don't need one\r\n- Or is has been resolve\r\n","created_at":"2016-12-22T23:24:22Z","updated_at":"2016-12-22T23:45:43Z","html_url":"https://github.com/apache/spark/pull/16308#discussion_r93712892","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/16308","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/93712892"},"html":{"href":"https://github.com/apache/spark/pull/16308#discussion_r93712892"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/16308"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/16308","id":98299866,"html_url":"https://github.com/apache/spark/pull/16308","diff_url":"https://github.com/apache/spark/pull/16308.diff","patch_url":"https://github.com/apache/spark/pull/16308.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/16308","number":16308,"state":"open","locked":false,"title":"[SPARK-18936][SQL] Infrastructure for session local timezone support.","user":{"login":"ueshin","id":506656,"avatar_url":"https://avatars.githubusercontent.com/u/506656?v=3","gravatar_id":"","url":"https://api.github.com/users/ueshin","html_url":"https://github.com/ueshin","followers_url":"https://api.github.com/users/ueshin/followers","following_url":"https://api.github.com/users/ueshin/following{/other_user}","gists_url":"https://api.github.com/users/ueshin/gists{/gist_id}","starred_url":"https://api.github.com/users/ueshin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ueshin/subscriptions","organizations_url":"https://api.github.com/users/ueshin/orgs","repos_url":"https://api.github.com/users/ueshin/repos","events_url":"https://api.github.com/users/ueshin/events{/privacy}","received_events_url":"https://api.github.com/users/ueshin/received_events","type":"User","site_admin":false},"body":"## What changes were proposed in this pull request?\r\n\r\nAs of Spark 2.1, Spark SQL assumes the machine timezone for datetime manipulation, which is bad if users are not in the same timezones as the machines, or if different users have different timezones.\r\n\r\nWe should introduce a session local timezone setting that is used for execution.\r\n\r\nAn explicit non-goal is locale handling.\r\n\r\n### Semantics\r\n\r\nSetting the session local timezone means that the timezone-aware expressions listed below should use the timezone to evaluate values, and also it should be used to convert (cast) between string and timestamp or between timestamp and date.\r\n\r\n- `CurrentDate`\r\n- `CurrentBatchTimestamp`\r\n- `Hour`\r\n- `Minute`\r\n- `Second`\r\n- `DateFormatClass`\r\n- `ToUnixTimestamp`\r\n- `UnixTimestamp`\r\n- `FromUnixTime`\r\n\r\nand below are implicitly timezone-aware through cast from timestamp to date:\r\n\r\n- `DayOfYear`\r\n- `Year`\r\n- `Quarter`\r\n- `Month`\r\n- `DayOfMonth`\r\n- `WeekOfYear`\r\n- `LastDay`\r\n- `NextDay`\r\n- `TruncDate`\r\n\r\nFor example, if you have timestamp `\"2016-01-01 00:00:00\"` in `GMT`, the values evaluated by some of timezone-aware expressions are:\r\n\r\n```scala\r\nscala> val df = Seq(new java.sql.Timestamp(1451606400000L)).toDF(\"ts\")\r\ndf: org.apache.spark.sql.DataFrame = [ts: timestamp]\r\n\r\nscala> df.selectExpr(\"cast(ts as string)\", \"year(ts)\", \"month(ts)\", \"dayofmonth(ts)\", \"hour(ts)\", \"minute(ts)\", \"second(ts)\").show(truncate = false)\r\n+-------------------+----------------------+-----------------------+----------------------------+--------+----------+----------+\r\n|ts                 |year(CAST(ts AS DATE))|month(CAST(ts AS DATE))|dayofmonth(CAST(ts AS DATE))|hour(ts)|minute(ts)|second(ts)|\r\n+-------------------+----------------------+-----------------------+----------------------------+--------+----------+----------+\r\n|2016-01-01 00:00:00|2016                  |1                      |1                           |0       |0         |0         |\r\n+-------------------+----------------------+-----------------------+----------------------------+--------+----------+----------+\r\n```\r\n\r\nwhereas setting the session local timezone to `\"PST\"`, they are:\r\n\r\n```scala\r\nscala> spark.conf.set(\"spark.sql.session.timeZone\", \"PST\")\r\n\r\nscala> df.selectExpr(\"cast(ts as string)\", \"year(ts)\", \"month(ts)\", \"dayofmonth(ts)\", \"hour(ts)\", \"minute(ts)\", \"second(ts)\").show(truncate = false)\r\n+-------------------+----------------------+-----------------------+----------------------------+--------+----------+----------+\r\n|ts                 |year(CAST(ts AS DATE))|month(CAST(ts AS DATE))|dayofmonth(CAST(ts AS DATE))|hour(ts)|minute(ts)|second(ts)|\r\n+-------------------+----------------------+-----------------------+----------------------------+--------+----------+----------+\r\n|2015-12-31 16:00:00|2015                  |12                     |31                          |16      |0         |0         |\r\n+-------------------+----------------------+-----------------------+----------------------------+--------+----------+----------+\r\n```\r\n\r\nNotice that even if you set the session local timezone, it affects only in `DataFrame` operations, neither in `Dataset` operations, `RDD` operations nor in `ScalaUDF`s. You need to properly handle timezone by yourself.\r\n\r\n\r\n### Design of the fix\r\n\r\nI introduced an analyzer to pass session local timezone to timezone-aware expressions and modified DateTimeUtils to take the timezone argument.\r\n\r\n## How was this patch tested?\r\n\r\nExisting tests and added tests for timezone aware expressions.\r\n\r\n","created_at":"2016-12-16T09:09:06Z","updated_at":"2016-12-22T23:45:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"21ae8700b0f15fb19814f7d1daf76f37213c2816","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/16308/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/16308/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/16308/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/4b6900cf6d182d87a545d736d320c6229fb8251d","head":{"label":"ueshin:issues/SPARK-18350","ref":"issues/SPARK-18350","sha":"4b6900cf6d182d87a545d736d320c6229fb8251d","user":{"login":"ueshin","id":506656,"avatar_url":"https://avatars.githubusercontent.com/u/506656?v=3","gravatar_id":"","url":"https://api.github.com/users/ueshin","html_url":"https://github.com/ueshin","followers_url":"https://api.github.com/users/ueshin/followers","following_url":"https://api.github.com/users/ueshin/following{/other_user}","gists_url":"https://api.github.com/users/ueshin/gists{/gist_id}","starred_url":"https://api.github.com/users/ueshin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ueshin/subscriptions","organizations_url":"https://api.github.com/users/ueshin/orgs","repos_url":"https://api.github.com/users/ueshin/repos","events_url":"https://api.github.com/users/ueshin/events{/privacy}","received_events_url":"https://api.github.com/users/ueshin/received_events","type":"User","site_admin":false},"repo":{"id":17234665,"name":"apache-spark","full_name":"ueshin/apache-spark","owner":{"login":"ueshin","id":506656,"avatar_url":"https://avatars.githubusercontent.com/u/506656?v=3","gravatar_id":"","url":"https://api.github.com/users/ueshin","html_url":"https://github.com/ueshin","followers_url":"https://api.github.com/users/ueshin/followers","following_url":"https://api.github.com/users/ueshin/following{/other_user}","gists_url":"https://api.github.com/users/ueshin/gists{/gist_id}","starred_url":"https://api.github.com/users/ueshin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ueshin/subscriptions","organizations_url":"https://api.github.com/users/ueshin/orgs","repos_url":"https://api.github.com/users/ueshin/repos","events_url":"https://api.github.com/users/ueshin/events{/privacy}","received_events_url":"https://api.github.com/users/ueshin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ueshin/apache-spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/ueshin/apache-spark","forks_url":"https://api.github.com/repos/ueshin/apache-spark/forks","keys_url":"https://api.github.com/repos/ueshin/apache-spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ueshin/apache-spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ueshin/apache-spark/teams","hooks_url":"https://api.github.com/repos/ueshin/apache-spark/hooks","issue_events_url":"https://api.github.com/repos/ueshin/apache-spark/issues/events{/number}","events_url":"https://api.github.com/repos/ueshin/apache-spark/events","assignees_url":"https://api.github.com/repos/ueshin/apache-spark/assignees{/user}","branches_url":"https://api.github.com/repos/ueshin/apache-spark/branches{/branch}","tags_url":"https://api.github.com/repos/ueshin/apache-spark/tags","blobs_url":"https://api.github.com/repos/ueshin/apache-spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ueshin/apache-spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ueshin/apache-spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/ueshin/apache-spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ueshin/apache-spark/statuses/{sha}","languages_url":"https://api.github.com/repos/ueshin/apache-spark/languages","stargazers_url":"https://api.github.com/repos/ueshin/apache-spark/stargazers","contributors_url":"https://api.github.com/repos/ueshin/apache-spark/contributors","subscribers_url":"https://api.github.com/repos/ueshin/apache-spark/subscribers","subscription_url":"https://api.github.com/repos/ueshin/apache-spark/subscription","commits_url":"https://api.github.com/repos/ueshin/apache-spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/ueshin/apache-spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/ueshin/apache-spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/ueshin/apache-spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/ueshin/apache-spark/contents/{+path}","compare_url":"https://api.github.com/repos/ueshin/apache-spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ueshin/apache-spark/merges","archive_url":"https://api.github.com/repos/ueshin/apache-spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ueshin/apache-spark/downloads","issues_url":"https://api.github.com/repos/ueshin/apache-spark/issues{/number}","pulls_url":"https://api.github.com/repos/ueshin/apache-spark/pulls{/number}","milestones_url":"https://api.github.com/repos/ueshin/apache-spark/milestones{/number}","notifications_url":"https://api.github.com/repos/ueshin/apache-spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ueshin/apache-spark/labels{/name}","releases_url":"https://api.github.com/repos/ueshin/apache-spark/releases{/id}","deployments_url":"https://api.github.com/repos/ueshin/apache-spark/deployments","created_at":"2014-02-27T03:10:47Z","updated_at":"2016-10-22T03:00:17Z","pushed_at":"2016-12-22T21:00:16Z","git_url":"git://github.com/ueshin/apache-spark.git","ssh_url":"git@github.com:ueshin/apache-spark.git","clone_url":"https://github.com/ueshin/apache-spark.git","svn_url":"https://github.com/ueshin/apache-spark","homepage":null,"size":259644,"stargazers_count":1,"watchers_count":1,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"5857b9ac2d9808d9b89a5b29620b5052e2beebf5","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":17165658,"name":"spark","full_name":"apache/spark","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/spark","description":"Mirror of Apache Spark","fork":false,"url":"https://api.github.com/repos/apache/spark","forks_url":"https://api.github.com/repos/apache/spark/forks","keys_url":"https://api.github.com/repos/apache/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/spark/teams","hooks_url":"https://api.github.com/repos/apache/spark/hooks","issue_events_url":"https://api.github.com/repos/apache/spark/issues/events{/number}","events_url":"https://api.github.com/repos/apache/spark/events","assignees_url":"https://api.github.com/repos/apache/spark/assignees{/user}","branches_url":"https://api.github.com/repos/apache/spark/branches{/branch}","tags_url":"https://api.github.com/repos/apache/spark/tags","blobs_url":"https://api.github.com/repos/apache/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/spark/languages","stargazers_url":"https://api.github.com/repos/apache/spark/stargazers","contributors_url":"https://api.github.com/repos/apache/spark/contributors","subscribers_url":"https://api.github.com/repos/apache/spark/subscribers","subscription_url":"https://api.github.com/repos/apache/spark/subscription","commits_url":"https://api.github.com/repos/apache/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/spark/contents/{+path}","compare_url":"https://api.github.com/repos/apache/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/spark/merges","archive_url":"https://api.github.com/repos/apache/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/spark/downloads","issues_url":"https://api.github.com/repos/apache/spark/issues{/number}","pulls_url":"https://api.github.com/repos/apache/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/spark/labels{/name}","releases_url":"https://api.github.com/repos/apache/spark/releases{/id}","deployments_url":"https://api.github.com/repos/apache/spark/deployments","created_at":"2014-02-25T08:00:08Z","updated_at":"2016-12-22T19:39:53Z","pushed_at":"2016-12-22T23:12:47Z","git_url":"git://github.com/apache/spark.git","ssh_url":"git@github.com:apache/spark.git","clone_url":"https://github.com/apache/spark.git","svn_url":"https://github.com/apache/spark","homepage":null,"size":258969,"stargazers_count":11172,"watchers_count":11172,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":10481,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":443,"forks":10481,"open_issues":443,"watchers":11172,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/16308"},"html":{"href":"https://github.com/apache/spark/pull/16308"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/16308"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/16308/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/16308/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/16308/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/4b6900cf6d182d87a545d736d320c6229fb8251d"}}}}
{"actor":{"display_login":"hvanhovell"}}