{"action":"created","issue":{"url":"https://api.github.com/repos/apache/spark/issues/22395","repository_url":"https://api.github.com/repos/apache/spark","labels_url":"https://api.github.com/repos/apache/spark/issues/22395/labels{/name}","comments_url":"https://api.github.com/repos/apache/spark/issues/22395/comments","events_url":"https://api.github.com/repos/apache/spark/issues/22395/events","html_url":"https://github.com/apache/spark/pull/22395","id":359112503,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE0NjgyNjUy","number":22395,"title":"[SPARK-16323][SQL] Add IntegralDivide expression","user":{"login":"mgaido91","id":8821783,"node_id":"MDQ6VXNlcjg4MjE3ODM=","avatar_url":"https://avatars1.githubusercontent.com/u/8821783?v=4","gravatar_id":"","url":"https://api.github.com/users/mgaido91","html_url":"https://github.com/mgaido91","followers_url":"https://api.github.com/users/mgaido91/followers","following_url":"https://api.github.com/users/mgaido91/following{/other_user}","gists_url":"https://api.github.com/users/mgaido91/gists{/gist_id}","starred_url":"https://api.github.com/users/mgaido91/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mgaido91/subscriptions","organizations_url":"https://api.github.com/users/mgaido91/orgs","repos_url":"https://api.github.com/users/mgaido91/repos","events_url":"https://api.github.com/users/mgaido91/events{/privacy}","received_events_url":"https://api.github.com/users/mgaido91/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-09-11T15:57:16Z","updated_at":"2018-09-11T19:31:46Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/22395","html_url":"https://github.com/apache/spark/pull/22395","diff_url":"https://github.com/apache/spark/pull/22395.diff","patch_url":"https://github.com/apache/spark/pull/22395.patch"},"body":"## What changes were proposed in this pull request?\r\n\r\nThe PR takes over #14036 and it introduces a new expression `IntegralDivide` in order to avoid the several unneded cast added previously.\r\n\r\nIn order to prove the performance gain, the following benchmark has been run:\r\n\r\n```\r\n  test(\"Benchmark IntegralDivide\") {\r\n    val r = new scala.util.Random(91)\r\n    val nData = 1000000\r\n    val testDataInt = (1 to nData).map(_ => (r.nextInt(), r.nextInt()))\r\n    val testDataLong = (1 to nData).map(_ => (r.nextLong(), r.nextLong()))\r\n    val testDataShort = (1 to nData).map(_ => (r.nextInt().toShort, r.nextInt().toShort))\r\n\r\n    // old code\r\n    val oldExprsInt = testDataInt.map(x =>\r\n      Cast(Divide(Cast(Literal(x._1), DoubleType), Cast(Literal(x._2), DoubleType)), LongType))\r\n    val oldExprsLong = testDataLong.map(x =>\r\n      Cast(Divide(Cast(Literal(x._1), DoubleType), Cast(Literal(x._2), DoubleType)), LongType))\r\n    val oldExprsShort = testDataShort.map(x =>\r\n      Cast(Divide(Cast(Literal(x._1), DoubleType), Cast(Literal(x._2), DoubleType)), LongType))\r\n\r\n    // new code\r\n    val newExprsInt = testDataInt.map(x => IntegralDivide(x._1, x._2))\r\n    val newExprsLong = testDataLong.map(x => IntegralDivide(x._1, x._2))\r\n    val newExprsShort = testDataShort.map(x => IntegralDivide(x._1, x._2))\r\n\r\n\r\n    Seq((\"Long\", \"old\", oldExprsLong),\r\n      (\"Long\", \"new\", newExprsLong),\r\n      (\"Int\", \"old\", oldExprsInt),\r\n      (\"Int\", \"new\", newExprsShort),\r\n      (\"Short\", \"old\", oldExprsShort),\r\n      (\"Short\", \"new\", oldExprsShort)).foreach { case (dt, t, ds) =>\r\n      val start = System.nanoTime()\r\n      ds.foreach(e => e.eval(EmptyRow))\r\n      val endNoCodegen = System.nanoTime()\r\n      println(s\"Running $nData op with $t code on $dt (no-codegen): ${(endNoCodegen - start) / 1000000} ms\")\r\n    }\r\n  }\r\n```\r\n\r\nThe results on my laptop are:\r\n\r\n```\r\nRunning 1000000 op with old code on Long (no-codegen): 600 ms\r\nRunning 1000000 op with new code on Long (no-codegen): 112 ms\r\nRunning 1000000 op with old code on Int (no-codegen): 560 ms\r\nRunning 1000000 op with new code on Int (no-codegen): 135 ms\r\nRunning 1000000 op with old code on Short (no-codegen): 317 ms\r\nRunning 1000000 op with new code on Short (no-codegen): 153 ms\r\n```\r\n\r\nShowing a 2-5X improvement. The benchmark doesn't include code generation as it is pretty hard to test the performance there as for such simple operations the most of the time is spent in the code generation/compilation process.\r\n\r\n## How was this patch tested?\r\n\r\nadded UTs\r\n"},"comment":{"url":"https://api.github.com/repos/apache/spark/issues/comments/420395278","html_url":"https://github.com/apache/spark/pull/22395#issuecomment-420395278","issue_url":"https://api.github.com/repos/apache/spark/issues/22395","id":420395278,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMDM5NTI3OA==","user":{"login":"SparkQA","id":8108735,"node_id":"MDQ6VXNlcjgxMDg3MzU=","avatar_url":"https://avatars1.githubusercontent.com/u/8108735?v=4","gravatar_id":"","url":"https://api.github.com/users/SparkQA","html_url":"https://github.com/SparkQA","followers_url":"https://api.github.com/users/SparkQA/followers","following_url":"https://api.github.com/users/SparkQA/following{/other_user}","gists_url":"https://api.github.com/users/SparkQA/gists{/gist_id}","starred_url":"https://api.github.com/users/SparkQA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SparkQA/subscriptions","organizations_url":"https://api.github.com/users/SparkQA/orgs","repos_url":"https://api.github.com/users/SparkQA/repos","events_url":"https://api.github.com/users/SparkQA/events{/privacy}","received_events_url":"https://api.github.com/users/SparkQA/received_events","type":"User","site_admin":false},"created_at":"2018-09-11T19:31:46Z","updated_at":"2018-09-11T19:31:46Z","author_association":"NONE","body":"**[Test build #95954 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/95954/testReport)** for PR 22395 at commit [`649b458`](https://github.com/apache/spark/commit/649b45875e81e47ba3282150b669f766fbe806ba).\n * This patch **fails Spark unit tests**.\n * This patch merges cleanly.\n * This patch adds the following public classes _(experimental)_:\n  * `case class IntegralDivide(left: Expression, right: Expression) extends DivModLike `"}}
{"actor":{"display_login":"SparkQA"}}