{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/70562757","id":70562757,"diff_hunk":"@@ -249,11 +241,12 @@ case class Divide(left: Expression, right: Expression)\n       s\"${eval2.value} == 0\"\n     }\n     val javaType = ctx.javaType(dataType)\n-    val divide = if (dataType.isInstanceOf[DecimalType]) {\n+    val divide = if (dataType.isInstanceOf[DecimalType] || dataType.isInstanceOf[DoubleType]) {\n       s\"${eval1.value}.$decimalMethod(${eval2.value})\"\n     } else {\n-      s\"($javaType)(${eval1.value} $symbol ${eval2.value})\"\n+      s\"($javaType)(${eval1.value} $decimalMethod ${eval2.value})\"","path":"sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/arithmetic.scala","position":32,"original_position":32,"commit_id":"d057546cd1132b4ece05df2a4a7d721ac65ca600","original_commit_id":"d057546cd1132b4ece05df2a4a7d721ac65ca600","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},"body":"ok I see the problem. Since `symbol` is also used in the string format of arithmetic expression, `IntegerDivide` has to override it.\r\n\r\nI think we can:\r\n\r\n1. inline the operator in generated code, e.g. `($javaType)(${eval1.value} / ${eval2.value})` instead of `($javaType)(${eval1.value} $symbol ${eval2.value})`\r\n2. don't override `decimalMethod` as it's useless in the 2 division expressions.","created_at":"2016-07-13T04:23:20Z","updated_at":"2016-07-13T04:23:20Z","html_url":"https://github.com/apache/spark/pull/14036#discussion_r70562757","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/14036","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/70562757"},"html":{"href":"https://github.com/apache/spark/pull/14036#discussion_r70562757"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/14036"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/14036","id":76084428,"html_url":"https://github.com/apache/spark/pull/14036","diff_url":"https://github.com/apache/spark/pull/14036.diff","patch_url":"https://github.com/apache/spark/pull/14036.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/14036","number":14036,"state":"open","locked":false,"title":"[SPARK-16323] [SQL] Add IntegerDivide to avoid unnecessary cast","user":{"login":"techaddict","id":1378755,"avatar_url":"https://avatars.githubusercontent.com/u/1378755?v=3","gravatar_id":"","url":"https://api.github.com/users/techaddict","html_url":"https://github.com/techaddict","followers_url":"https://api.github.com/users/techaddict/followers","following_url":"https://api.github.com/users/techaddict/following{/other_user}","gists_url":"https://api.github.com/users/techaddict/gists{/gist_id}","starred_url":"https://api.github.com/users/techaddict/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/techaddict/subscriptions","organizations_url":"https://api.github.com/users/techaddict/orgs","repos_url":"https://api.github.com/users/techaddict/repos","events_url":"https://api.github.com/users/techaddict/events{/privacy}","received_events_url":"https://api.github.com/users/techaddict/received_events","type":"User","site_admin":false},"body":"## What changes were proposed in this pull request?\r\nAdd IntegerDivide to avoid unnecessary cast\r\n\r\nBefore:\r\n```\r\nscala> spark.sql(\"select 6 div 3\").explain(true)\r\n...\r\n== Analyzed Logical Plan ==\r\nCAST((6 / 3) AS BIGINT): bigint\r\nProject [cast((cast(6 as double) / cast(3 as double)) as bigint) AS\r\nCAST((6 / 3) AS BIGINT)#5L]\r\n+- OneRowRelation$\r\n...\r\n```\r\n\r\nAfter:\r\n```\r\nscala> spark.sql(\"select 6 div 3\").explain(true)\r\n...\r\n== Analyzed Logical Plan ==\r\n(6 / 3): int\r\nProject [(6 / 3) AS (6 / 3)#11]\r\n+- OneRowRelation$\r\n...\r\n```\r\n\r\n## How was this patch tested?\r\nExisting Tests and added new ones","created_at":"2016-07-03T09:03:29Z","updated_at":"2016-07-13T04:23:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"45aa38b245d1094d4eee6231ac8e27055129cf25","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/14036/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/14036/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/14036/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/d057546cd1132b4ece05df2a4a7d721ac65ca600","head":{"label":"techaddict:SPARK-16323","ref":"SPARK-16323","sha":"d057546cd1132b4ece05df2a4a7d721ac65ca600","user":{"login":"techaddict","id":1378755,"avatar_url":"https://avatars.githubusercontent.com/u/1378755?v=3","gravatar_id":"","url":"https://api.github.com/users/techaddict","html_url":"https://github.com/techaddict","followers_url":"https://api.github.com/users/techaddict/followers","following_url":"https://api.github.com/users/techaddict/following{/other_user}","gists_url":"https://api.github.com/users/techaddict/gists{/gist_id}","starred_url":"https://api.github.com/users/techaddict/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/techaddict/subscriptions","organizations_url":"https://api.github.com/users/techaddict/orgs","repos_url":"https://api.github.com/users/techaddict/repos","events_url":"https://api.github.com/users/techaddict/events{/privacy}","received_events_url":"https://api.github.com/users/techaddict/received_events","type":"User","site_admin":false},"repo":{"id":18507796,"name":"spark","full_name":"techaddict/spark","owner":{"login":"techaddict","id":1378755,"avatar_url":"https://avatars.githubusercontent.com/u/1378755?v=3","gravatar_id":"","url":"https://api.github.com/users/techaddict","html_url":"https://github.com/techaddict","followers_url":"https://api.github.com/users/techaddict/followers","following_url":"https://api.github.com/users/techaddict/following{/other_user}","gists_url":"https://api.github.com/users/techaddict/gists{/gist_id}","starred_url":"https://api.github.com/users/techaddict/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/techaddict/subscriptions","organizations_url":"https://api.github.com/users/techaddict/orgs","repos_url":"https://api.github.com/users/techaddict/repos","events_url":"https://api.github.com/users/techaddict/events{/privacy}","received_events_url":"https://api.github.com/users/techaddict/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/techaddict/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/techaddict/spark","forks_url":"https://api.github.com/repos/techaddict/spark/forks","keys_url":"https://api.github.com/repos/techaddict/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/techaddict/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/techaddict/spark/teams","hooks_url":"https://api.github.com/repos/techaddict/spark/hooks","issue_events_url":"https://api.github.com/repos/techaddict/spark/issues/events{/number}","events_url":"https://api.github.com/repos/techaddict/spark/events","assignees_url":"https://api.github.com/repos/techaddict/spark/assignees{/user}","branches_url":"https://api.github.com/repos/techaddict/spark/branches{/branch}","tags_url":"https://api.github.com/repos/techaddict/spark/tags","blobs_url":"https://api.github.com/repos/techaddict/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/techaddict/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/techaddict/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/techaddict/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/techaddict/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/techaddict/spark/languages","stargazers_url":"https://api.github.com/repos/techaddict/spark/stargazers","contributors_url":"https://api.github.com/repos/techaddict/spark/contributors","subscribers_url":"https://api.github.com/repos/techaddict/spark/subscribers","subscription_url":"https://api.github.com/repos/techaddict/spark/subscription","commits_url":"https://api.github.com/repos/techaddict/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/techaddict/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/techaddict/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/techaddict/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/techaddict/spark/contents/{+path}","compare_url":"https://api.github.com/repos/techaddict/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/techaddict/spark/merges","archive_url":"https://api.github.com/repos/techaddict/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/techaddict/spark/downloads","issues_url":"https://api.github.com/repos/techaddict/spark/issues{/number}","pulls_url":"https://api.github.com/repos/techaddict/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/techaddict/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/techaddict/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/techaddict/spark/labels{/name}","releases_url":"https://api.github.com/repos/techaddict/spark/releases{/id}","deployments_url":"https://api.github.com/repos/techaddict/spark/deployments","created_at":"2014-04-07T06:05:50Z","updated_at":"2016-03-31T13:35:48Z","pushed_at":"2016-07-13T03:58:32Z","git_url":"git://github.com/techaddict/spark.git","ssh_url":"git@github.com:techaddict/spark.git","clone_url":"https://github.com/techaddict/spark.git","svn_url":"https://github.com/techaddict/spark","homepage":null,"size":168052,"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":"6cb75db9ab1a4f227069bec2763b89546b88b0ee","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-07-13T03:11:20Z","pushed_at":"2016-07-13T03:58:33Z","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":497953,"stargazers_count":9284,"watchers_count":9284,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":8606,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":427,"forks":8606,"open_issues":427,"watchers":9284,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/14036"},"html":{"href":"https://github.com/apache/spark/pull/14036"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/14036"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/14036/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/14036/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/14036/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/d057546cd1132b4ece05df2a4a7d721ac65ca600"}}}}
{"actor":{"display_login":"cloud-fan"}}