{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/34369359","id":34369359,"diff_hunk":"@@ -54,3 +60,341 @@ case class CurrentTimestamp() extends LeafExpression {\n     System.currentTimeMillis() * 1000L\n   }\n }\n+\n+/**\n+ * Abstract class for create time format expressions.\n+ */\n+abstract class TimeFormatExpression extends UnaryExpression with ExpectsInputTypes {\n+  self: Product =>\n+\n+  protected val factorToMilli: Int\n+\n+  protected val cntPerInterval: Int\n+\n+  override def inputTypes: Seq[AbstractDataType] = Seq(TimestampType)\n+\n+  override def dataType: DataType = IntegerType\n+\n+  override protected def nullSafeEval(timestamp: Any): Any = {\n+    val time = timestamp.asInstanceOf[Long] / 1000\n+    val longTime: Long = time + TimeZone.getDefault.getOffset(time)\n+    ((longTime / factorToMilli) % cntPerInterval).toInt\n+  }\n+\n+  override def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {\n+    val tz = classOf[TimeZone].getName\n+    defineCodeGen(ctx, ev, (c) =>\n+      s\"\"\"(${ctx.javaType(dataType)})\n+            ((($c / 1000) + $tz.getDefault().getOffset($c / 1000))\n+                / $factorToMilli % $cntPerInterval)\"\"\"\n+    )\n+  }\n+}\n+\n+case class Hour(child: Expression) extends TimeFormatExpression {\n+\n+  override protected val factorToMilli: Int = 1000 * 3600\n+\n+  override protected val cntPerInterval: Int = 24\n+}\n+\n+case class Minute(child: Expression) extends TimeFormatExpression {\n+\n+  override protected val factorToMilli: Int = 1000 * 60\n+\n+  override protected val cntPerInterval: Int = 60\n+}\n+\n+case class Second(child: Expression) extends UnaryExpression with ExpectsInputTypes {\n+\n+  override def inputTypes: Seq[AbstractDataType] = Seq(TimestampType)\n+\n+  override def dataType: DataType = IntegerType\n+\n+  override protected def nullSafeEval(time: Any): Any = {\n+    time.asInstanceOf[Long] / 1000L / 1000L % 60L\n+  }\n+\n+  override protected def genCode(ctx: CodeGenContext, ev: GeneratedExpressionCode): String = {\n+    nullSafeCodeGen(ctx, ev, (time) => {\n+      s\"\"\"${ev.primitive} = (${ctx.javaType(IntegerType)}) ($time / 1000L / 1000L % 60L);\"\"\"","path":"sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/datetimeFunctions.scala","position":77,"original_position":77,"commit_id":"ad17e9673a82ae79c76caf91cc8aa56679c5b103","original_commit_id":"ad17e9673a82ae79c76caf91cc8aa56679c5b103","user":{"login":"davies","id":40902,"avatar_url":"https://avatars.githubusercontent.com/u/40902?v=3","gravatar_id":"","url":"https://api.github.com/users/davies","html_url":"https://github.com/davies","followers_url":"https://api.github.com/users/davies/followers","following_url":"https://api.github.com/users/davies/following{/other_user}","gists_url":"https://api.github.com/users/davies/gists{/gist_id}","starred_url":"https://api.github.com/users/davies/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davies/subscriptions","organizations_url":"https://api.github.com/users/davies/orgs","repos_url":"https://api.github.com/users/davies/repos","events_url":"https://api.github.com/users/davies/events{/privacy}","received_events_url":"https://api.github.com/users/davies/received_events","type":"User","site_admin":false},"body":"defineCodeGen(ctx, ev, time => s\"(int) ($time / 1000 / 1000 % 60)\"","created_at":"2015-07-10T16:06:27Z","updated_at":"2015-07-10T16:06:27Z","html_url":"https://github.com/apache/spark/pull/6981#discussion_r34369359","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/6981","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/34369359"},"html":{"href":"https://github.com/apache/spark/pull/6981#discussion_r34369359"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/6981"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/6981","id":38420199,"html_url":"https://github.com/apache/spark/pull/6981","diff_url":"https://github.com/apache/spark/pull/6981.diff","patch_url":"https://github.com/apache/spark/pull/6981.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/6981","number":6981,"state":"open","locked":false,"title":"[SPARK-8199][SPARK-8184][SPARK-8183][SPARK-8182][SPARK-8181][SPARK-8180][SPARK-8179][SPARK-8177][SPARK-8178][SQL][WIP] date functions","user":{"login":"tarekauel","id":5320817,"avatar_url":"https://avatars.githubusercontent.com/u/5320817?v=3","gravatar_id":"","url":"https://api.github.com/users/tarekauel","html_url":"https://github.com/tarekauel","followers_url":"https://api.github.com/users/tarekauel/followers","following_url":"https://api.github.com/users/tarekauel/following{/other_user}","gists_url":"https://api.github.com/users/tarekauel/gists{/gist_id}","starred_url":"https://api.github.com/users/tarekauel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tarekauel/subscriptions","organizations_url":"https://api.github.com/users/tarekauel/orgs","repos_url":"https://api.github.com/users/tarekauel/repos","events_url":"https://api.github.com/users/tarekauel/events{/privacy}","received_events_url":"https://api.github.com/users/tarekauel/received_events","type":"User","site_admin":false},"body":"Jira:\r\nhttps://issues.apache.org/jira/browse/SPARK-8199\r\nhttps://issues.apache.org/jira/browse/SPARK-8184\r\nhttps://issues.apache.org/jira/browse/SPARK-8183\r\nhttps://issues.apache.org/jira/browse/SPARK-8182\r\nhttps://issues.apache.org/jira/browse/SPARK-8181\r\nhttps://issues.apache.org/jira/browse/SPARK-8180\r\nhttps://issues.apache.org/jira/browse/SPARK-8179\r\nhttps://issues.apache.org/jira/browse/SPARK-8177\r\nhttps://issues.apache.org/jira/browse/SPARK-8179\r\n\r\nRegarding `day`and `dayofmonth` are both necessary?\r\n\r\n~~I am going to add `Quarter` to this PR as well.~~ Done.\r\n\r\n~~As soon as the Scala coding is reviewed and discussed, I'll add the python api.~~ Done","created_at":"2015-06-24T08:53:02Z","updated_at":"2015-07-10T16:06:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"6f2a5bd1de2e58772dee4d72cccd0e4489e390f5","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/6981/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/6981/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/6981/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/ad17e9673a82ae79c76caf91cc8aa56679c5b103","head":{"label":"tarekauel:SPARK-8199","ref":"SPARK-8199","sha":"ad17e9673a82ae79c76caf91cc8aa56679c5b103","user":{"login":"tarekauel","id":5320817,"avatar_url":"https://avatars.githubusercontent.com/u/5320817?v=3","gravatar_id":"","url":"https://api.github.com/users/tarekauel","html_url":"https://github.com/tarekauel","followers_url":"https://api.github.com/users/tarekauel/followers","following_url":"https://api.github.com/users/tarekauel/following{/other_user}","gists_url":"https://api.github.com/users/tarekauel/gists{/gist_id}","starred_url":"https://api.github.com/users/tarekauel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tarekauel/subscriptions","organizations_url":"https://api.github.com/users/tarekauel/orgs","repos_url":"https://api.github.com/users/tarekauel/repos","events_url":"https://api.github.com/users/tarekauel/events{/privacy}","received_events_url":"https://api.github.com/users/tarekauel/received_events","type":"User","site_admin":false},"repo":{"id":36629285,"name":"spark","full_name":"tarekauel/spark","owner":{"login":"tarekauel","id":5320817,"avatar_url":"https://avatars.githubusercontent.com/u/5320817?v=3","gravatar_id":"","url":"https://api.github.com/users/tarekauel","html_url":"https://github.com/tarekauel","followers_url":"https://api.github.com/users/tarekauel/followers","following_url":"https://api.github.com/users/tarekauel/following{/other_user}","gists_url":"https://api.github.com/users/tarekauel/gists{/gist_id}","starred_url":"https://api.github.com/users/tarekauel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tarekauel/subscriptions","organizations_url":"https://api.github.com/users/tarekauel/orgs","repos_url":"https://api.github.com/users/tarekauel/repos","events_url":"https://api.github.com/users/tarekauel/events{/privacy}","received_events_url":"https://api.github.com/users/tarekauel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tarekauel/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/tarekauel/spark","forks_url":"https://api.github.com/repos/tarekauel/spark/forks","keys_url":"https://api.github.com/repos/tarekauel/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tarekauel/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tarekauel/spark/teams","hooks_url":"https://api.github.com/repos/tarekauel/spark/hooks","issue_events_url":"https://api.github.com/repos/tarekauel/spark/issues/events{/number}","events_url":"https://api.github.com/repos/tarekauel/spark/events","assignees_url":"https://api.github.com/repos/tarekauel/spark/assignees{/user}","branches_url":"https://api.github.com/repos/tarekauel/spark/branches{/branch}","tags_url":"https://api.github.com/repos/tarekauel/spark/tags","blobs_url":"https://api.github.com/repos/tarekauel/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tarekauel/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tarekauel/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/tarekauel/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tarekauel/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/tarekauel/spark/languages","stargazers_url":"https://api.github.com/repos/tarekauel/spark/stargazers","contributors_url":"https://api.github.com/repos/tarekauel/spark/contributors","subscribers_url":"https://api.github.com/repos/tarekauel/spark/subscribers","subscription_url":"https://api.github.com/repos/tarekauel/spark/subscription","commits_url":"https://api.github.com/repos/tarekauel/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/tarekauel/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/tarekauel/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/tarekauel/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/tarekauel/spark/contents/{+path}","compare_url":"https://api.github.com/repos/tarekauel/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tarekauel/spark/merges","archive_url":"https://api.github.com/repos/tarekauel/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tarekauel/spark/downloads","issues_url":"https://api.github.com/repos/tarekauel/spark/issues{/number}","pulls_url":"https://api.github.com/repos/tarekauel/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/tarekauel/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/tarekauel/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tarekauel/spark/labels{/name}","releases_url":"https://api.github.com/repos/tarekauel/spark/releases{/id}","created_at":"2015-06-01T00:48:26Z","updated_at":"2015-06-01T00:48:47Z","pushed_at":"2015-07-10T08:56:27Z","git_url":"git://github.com/tarekauel/spark.git","ssh_url":"git@github.com:tarekauel/spark.git","clone_url":"https://github.com/tarekauel/spark.git","svn_url":"https://github.com/tarekauel/spark","homepage":null,"size":112530,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"851e247caad0977cfd4998254d9602624e06539f","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}","created_at":"2014-02-25T08:00:08Z","updated_at":"2015-07-10T14:33:09Z","pushed_at":"2015-07-10T15:35:48Z","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":1503507,"stargazers_count":4705,"watchers_count":4705,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":4173,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":333,"forks":4173,"open_issues":333,"watchers":4705,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/6981"},"html":{"href":"https://github.com/apache/spark/pull/6981"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/6981"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/6981/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/6981/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/6981/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/ad17e9673a82ae79c76caf91cc8aa56679c5b103"}}}}