{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/90397578","pull_request_review_id":10915109,"id":90397578,"diff_hunk":"@@ -64,19 +64,74 @@ case class If(predicate: Expression, trueValue: Expression, falseValue: Expressi\n     val trueEval = trueValue.genCode(ctx)\n     val falseEval = falseValue.genCode(ctx)\n \n-    ev.copy(code = s\"\"\"\n-      ${condEval.code}\n-      boolean ${ev.isNull} = false;\n-      ${ctx.javaType(dataType)} ${ev.value} = ${ctx.defaultValue(dataType)};\n-      if (!${condEval.isNull} && ${condEval.value}) {\n-        ${trueEval.code}\n-        ${ev.isNull} = ${trueEval.isNull};\n-        ${ev.value} = ${trueEval.value};\n-      } else {\n-        ${falseEval.code}\n-        ${ev.isNull} = ${falseEval.isNull};\n-        ${ev.value} = ${falseEval.value};\n-      }\"\"\")\n+    // place generated code of condition, true value and false value in separate methods if\n+    // their code combined is large\n+    val combinedLength = condEval.code.length + trueEval.code.length + falseEval.code.length\n+    val generatedCode = if (combinedLength > 1024 &&\n+      // Split these expressions only if they are created from a row object\n+      (ctx.INPUT_ROW != null && ctx.currentVars == null)) {\n+\n+      val (condFuncName, condGlobalIsNull, condGlobalValue) =\n+        createAndAddFunction(ctx, condEval, predicate.dataType, \"evalIfCondExpr\")\n+      val (trueFuncName, trueGlobalIsNull, trueGlobalValue) =\n+        createAndAddFunction(ctx, trueEval, trueValue.dataType, \"evalIfTrueExpr\")\n+      val (falseFuncName, falseGlobalIsNull, falseGlobalValue) =\n+        createAndAddFunction(ctx, falseEval, falseValue.dataType, \"evalIfFalseExpr\")\n+      s\"\"\"\n+        $condFuncName(${ctx.INPUT_ROW});\n+        boolean ${ev.isNull} = false;\n+        ${ctx.javaType(dataType)} ${ev.value} = ${ctx.defaultValue(dataType)};\n+        if (!$condGlobalIsNull && $condGlobalValue) {\n+          $trueFuncName(${ctx.INPUT_ROW});\n+          ${ev.isNull} = $trueGlobalIsNull;\n+          ${ev.value} = $trueGlobalValue;\n+        } else {\n+          $falseFuncName(${ctx.INPUT_ROW});\n+          ${ev.isNull} = $falseGlobalIsNull;\n+          ${ev.value} = $falseGlobalValue;\n+        }\n+      \"\"\"\n+    }\n+    else {\n+      s\"\"\"\n+        ${condEval.code}\n+        boolean ${ev.isNull} = false;\n+        ${ctx.javaType(dataType)} ${ev.value} = ${ctx.defaultValue(dataType)};\n+        if (!${condEval.isNull} && ${condEval.value}) {\n+          ${trueEval.code}\n+          ${ev.isNull} = ${trueEval.isNull};\n+          ${ev.value} = ${trueEval.value};\n+        } else {\n+          ${falseEval.code}\n+          ${ev.isNull} = ${falseEval.isNull};\n+          ${ev.value} = ${falseEval.value};\n+        }\n+      \"\"\"\n+    }\n+\n+    ev.copy(code = generatedCode)\n+  }\n+\n+  private def createAndAddFunction(ctx: CodegenContext,","path":"sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/conditionalExpressions.scala","position":65,"original_position":65,"commit_id":"fd0ab340f375af7ed4f71f6833e1f548bdc4477c","original_commit_id":"fd0ab340f375af7ed4f71f6833e1f548bdc4477c","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":"the code style is still wrong, see https://github.com/apache/spark/pull/15620#discussion_r90185562","created_at":"2016-12-01T07:54:33Z","updated_at":"2016-12-01T07:54:33Z","html_url":"https://github.com/apache/spark/pull/15620#discussion_r90397578","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/15620","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/90397578"},"html":{"href":"https://github.com/apache/spark/pull/15620#discussion_r90397578"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/15620"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/15620","id":90772440,"html_url":"https://github.com/apache/spark/pull/15620","diff_url":"https://github.com/apache/spark/pull/15620.diff","patch_url":"https://github.com/apache/spark/pull/15620.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/15620","number":15620,"state":"open","locked":false,"title":"[SPARK-18091] [SQL] Deep if expressions cause Generated SpecificUnsafeProjection code to exceed JVM code size limit","user":{"login":"kapilsingh5050","id":15405233,"avatar_url":"https://avatars.githubusercontent.com/u/15405233?v=3","gravatar_id":"","url":"https://api.github.com/users/kapilsingh5050","html_url":"https://github.com/kapilsingh5050","followers_url":"https://api.github.com/users/kapilsingh5050/followers","following_url":"https://api.github.com/users/kapilsingh5050/following{/other_user}","gists_url":"https://api.github.com/users/kapilsingh5050/gists{/gist_id}","starred_url":"https://api.github.com/users/kapilsingh5050/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kapilsingh5050/subscriptions","organizations_url":"https://api.github.com/users/kapilsingh5050/orgs","repos_url":"https://api.github.com/users/kapilsingh5050/repos","events_url":"https://api.github.com/users/kapilsingh5050/events{/privacy}","received_events_url":"https://api.github.com/users/kapilsingh5050/received_events","type":"User","site_admin":false},"body":"## What changes were proposed in this pull request?\n\nFix for SPARK-18091 which is a bug related to large if expressions causing generated SpecificUnsafeProjection code to exceed JVM code size limit. \n\nThis PR changes if expression's code generation to place its predicate, true value and false value expressions' generated code in separate methods in context so as to never generate too long combined code.\n## How was this patch tested?\n\nAdded a unit test and also tested manually with the application (having transformations similar to the unit test) which caused the issue to be identified in the first place.\n","created_at":"2016-10-25T09:42:04Z","updated_at":"2016-12-01T07:54:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0fd00a64755d8277b6a5f434328d0fbecc19b871","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/15620/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/15620/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/15620/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/fd0ab340f375af7ed4f71f6833e1f548bdc4477c","head":{"label":"kapilsingh5050:SPARK-18091-IfCodegenFix","ref":"SPARK-18091-IfCodegenFix","sha":"fd0ab340f375af7ed4f71f6833e1f548bdc4477c","user":{"login":"kapilsingh5050","id":15405233,"avatar_url":"https://avatars.githubusercontent.com/u/15405233?v=3","gravatar_id":"","url":"https://api.github.com/users/kapilsingh5050","html_url":"https://github.com/kapilsingh5050","followers_url":"https://api.github.com/users/kapilsingh5050/followers","following_url":"https://api.github.com/users/kapilsingh5050/following{/other_user}","gists_url":"https://api.github.com/users/kapilsingh5050/gists{/gist_id}","starred_url":"https://api.github.com/users/kapilsingh5050/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kapilsingh5050/subscriptions","organizations_url":"https://api.github.com/users/kapilsingh5050/orgs","repos_url":"https://api.github.com/users/kapilsingh5050/repos","events_url":"https://api.github.com/users/kapilsingh5050/events{/privacy}","received_events_url":"https://api.github.com/users/kapilsingh5050/received_events","type":"User","site_admin":false},"repo":{"id":45231748,"name":"spark","full_name":"kapilsingh5050/spark","owner":{"login":"kapilsingh5050","id":15405233,"avatar_url":"https://avatars.githubusercontent.com/u/15405233?v=3","gravatar_id":"","url":"https://api.github.com/users/kapilsingh5050","html_url":"https://github.com/kapilsingh5050","followers_url":"https://api.github.com/users/kapilsingh5050/followers","following_url":"https://api.github.com/users/kapilsingh5050/following{/other_user}","gists_url":"https://api.github.com/users/kapilsingh5050/gists{/gist_id}","starred_url":"https://api.github.com/users/kapilsingh5050/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kapilsingh5050/subscriptions","organizations_url":"https://api.github.com/users/kapilsingh5050/orgs","repos_url":"https://api.github.com/users/kapilsingh5050/repos","events_url":"https://api.github.com/users/kapilsingh5050/events{/privacy}","received_events_url":"https://api.github.com/users/kapilsingh5050/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kapilsingh5050/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/kapilsingh5050/spark","forks_url":"https://api.github.com/repos/kapilsingh5050/spark/forks","keys_url":"https://api.github.com/repos/kapilsingh5050/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kapilsingh5050/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kapilsingh5050/spark/teams","hooks_url":"https://api.github.com/repos/kapilsingh5050/spark/hooks","issue_events_url":"https://api.github.com/repos/kapilsingh5050/spark/issues/events{/number}","events_url":"https://api.github.com/repos/kapilsingh5050/spark/events","assignees_url":"https://api.github.com/repos/kapilsingh5050/spark/assignees{/user}","branches_url":"https://api.github.com/repos/kapilsingh5050/spark/branches{/branch}","tags_url":"https://api.github.com/repos/kapilsingh5050/spark/tags","blobs_url":"https://api.github.com/repos/kapilsingh5050/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kapilsingh5050/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kapilsingh5050/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/kapilsingh5050/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kapilsingh5050/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/kapilsingh5050/spark/languages","stargazers_url":"https://api.github.com/repos/kapilsingh5050/spark/stargazers","contributors_url":"https://api.github.com/repos/kapilsingh5050/spark/contributors","subscribers_url":"https://api.github.com/repos/kapilsingh5050/spark/subscribers","subscription_url":"https://api.github.com/repos/kapilsingh5050/spark/subscription","commits_url":"https://api.github.com/repos/kapilsingh5050/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/kapilsingh5050/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/kapilsingh5050/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/kapilsingh5050/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/kapilsingh5050/spark/contents/{+path}","compare_url":"https://api.github.com/repos/kapilsingh5050/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kapilsingh5050/spark/merges","archive_url":"https://api.github.com/repos/kapilsingh5050/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kapilsingh5050/spark/downloads","issues_url":"https://api.github.com/repos/kapilsingh5050/spark/issues{/number}","pulls_url":"https://api.github.com/repos/kapilsingh5050/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/kapilsingh5050/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/kapilsingh5050/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kapilsingh5050/spark/labels{/name}","releases_url":"https://api.github.com/repos/kapilsingh5050/spark/releases{/id}","deployments_url":"https://api.github.com/repos/kapilsingh5050/spark/deployments","created_at":"2015-10-30T05:49:48Z","updated_at":"2016-10-25T09:28:46Z","pushed_at":"2016-11-30T14:09:29Z","git_url":"git://github.com/kapilsingh5050/spark.git","ssh_url":"git@github.com:kapilsingh5050/spark.git","clone_url":"https://github.com/kapilsingh5050/spark.git","svn_url":"https://github.com/kapilsingh5050/spark","homepage":null,"size":244332,"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":"c24076dcf867f8d7bb328055ca817bc09ad0c1d1","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-01T07:38:43Z","pushed_at":"2016-12-01T07:42:55Z","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":617005,"stargazers_count":10919,"watchers_count":10919,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":10194,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":450,"forks":10194,"open_issues":450,"watchers":10919,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/15620"},"html":{"href":"https://github.com/apache/spark/pull/15620"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/15620"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/15620/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/15620/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/15620/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/fd0ab340f375af7ed4f71f6833e1f548bdc4477c"}}}}
{"actor":{"display_login":"cloud-fan"}}