{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/63152997","id":63152997,"diff_hunk":"@@ -1560,7 +1561,15 @@ object EmbedSerializerInFilter extends Rule[LogicalPlan] {\n         val newCondition = condition transform {\n           case a: Attribute if a == d.output.head => d.deserializer\n         }\n-        Filter(newCondition, d.child)\n+        val filter = Filter(newCondition, d.child)\n+\n+        // Adds an extra Project here, to preserve the output expr id of `SerializeFromObject`.\n+        // We will remove it later in RemoveAliasOnlyProject rule.\n+        val objAttrs = filter.output.zip(s.output).map {\n+          case (fout, sout) =>\n+            Alias(fout, fout.name)(exprId = sout.exprId)","path":"sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala","position":21,"original_position":21,"commit_id":"2620409239e808578dbbd9e0099d32f041879f8e","original_commit_id":"2620409239e808578dbbd9e0099d32f041879f8e","user":{"login":"HyukjinKwon","id":6477701,"avatar_url":"https://avatars.githubusercontent.com/u/6477701?v=3","gravatar_id":"","url":"https://api.github.com/users/HyukjinKwon","html_url":"https://github.com/HyukjinKwon","followers_url":"https://api.github.com/users/HyukjinKwon/followers","following_url":"https://api.github.com/users/HyukjinKwon/following{/other_user}","gists_url":"https://api.github.com/users/HyukjinKwon/gists{/gist_id}","starred_url":"https://api.github.com/users/HyukjinKwon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HyukjinKwon/subscriptions","organizations_url":"https://api.github.com/users/HyukjinKwon/orgs","repos_url":"https://api.github.com/users/HyukjinKwon/repos","events_url":"https://api.github.com/users/HyukjinKwon/events{/privacy}","received_events_url":"https://api.github.com/users/HyukjinKwon/received_events","type":"User","site_admin":false},"body":"(it seems putting the case in the same line is preferred (`foreach { case (name, _) =>`) [scala-style-guide#pattern-matching](https://github.com/databricks/scala-style-guide#pattern-matching))","created_at":"2016-05-13T09:05:19Z","updated_at":"2016-05-13T09:05:19Z","html_url":"https://github.com/apache/spark/pull/13096#discussion_r63152997","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/13096","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/63152997"},"html":{"href":"https://github.com/apache/spark/pull/13096#discussion_r63152997"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/13096"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/13096","id":69963592,"html_url":"https://github.com/apache/spark/pull/13096","diff_url":"https://github.com/apache/spark/pull/13096.diff","patch_url":"https://github.com/apache/spark/pull/13096.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/13096","number":13096,"state":"open","locked":false,"title":"[SPARK-15313][SQL] EmbedSerializerInFilter rule should keep exprIds of output of surrounded SerializeFromObject.","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\nThe following code:\r\n\r\n```\r\nval ds = Seq((\"a\", 1), (\"b\", 2), (\"c\", 3)).toDS()\r\nds.filter(_._1 == \"b\").select(expr(\"_1\").as[String]).foreach(println(_))\r\n```\r\n\r\nthrows an Exception:\r\n\r\n```\r\norg.apache.spark.sql.catalyst.errors.package$TreeNodeException: Binding attribute, tree: _1#420\r\n at org.apache.spark.sql.catalyst.errors.package$.attachTree(package.scala:50)\r\n at org.apache.spark.sql.catalyst.expressions.BindReferences$$anonfun$bindReference$1.applyOrElse(BoundAttribute.scala:88)\r\n at org.apache.spark.sql.catalyst.expressions.BindReferences$$anonfun$bindReference$1.applyOrElse(BoundAttribute.scala:87)\r\n\r\n...\r\n Cause: java.lang.RuntimeException: Couldn't find _1#420 in [_1#416,_2#417]\r\n at scala.sys.package$.error(package.scala:27)\r\n at org.apache.spark.sql.catalyst.expressions.BindReferences$$anonfun$bindReference$1$$anonfun$applyOrElse$1.apply(BoundAttribute.scala:94)\r\n at org.apache.spark.sql.catalyst.expressions.BindReferences$$anonfun$bindReference$1$$anonfun$applyOrElse$1.apply(BoundAttribute.scala:88)\r\n at org.apache.spark.sql.catalyst.errors.package$.attachTree(package.scala:49)\r\n at org.apache.spark.sql.catalyst.expressions.BindReferences$$anonfun$bindReference$1.applyOrElse(BoundAttribute.scala:88)\r\n at org.apache.spark.sql.catalyst.expressions.BindReferences$$anonfun$bindReference$1.applyOrElse(BoundAttribute.scala:87)\r\n...\r\n```\r\n\r\nThis is because `EmbedSerializerInFilter` rule drops the `exprId`s of output of surrounded `SerializeFromObject`.\r\n\r\nThe analyzed and optimized plans of the above example are as follows:\r\n\r\n```\r\n== Analyzed Logical Plan ==\r\n_1: string\r\nProject [_1#420]\r\n+- SerializeFromObject [staticinvoke(class org.apache.spark.unsafe.types.UTF8String, StringType, fromString, input[0, scala.Tuple2]._1, true) AS _1#420,input[0, scala.Tuple2]._2 AS _2#421]\r\n   +- Filter <function1>.apply\r\n      +- DeserializeToObject newInstance(class scala.Tuple2), obj#419: scala.Tuple2\r\n         +- LocalRelation [_1#416,_2#417], [[0,1800000001,1,61],[0,1800000001,2,62],[0,1800000001,3,63]]\r\n\r\n== Optimized Logical Plan ==\r\n!Project [_1#420]\r\n+- Filter <function1>.apply\r\n   +- LocalRelation [_1#416,_2#417], [[0,1800000001,1,61],[0,1800000001,2,62],[0,1800000001,3,63]]\r\n```\r\n\r\nThis PR fixes `EmbedSerializerInFilter` rule to keep `exprId`s of output of surrounded `SerializeFromObject`.\r\n\r\nThe plans after this patch are as follows:\r\n\r\n```\r\n== Analyzed Logical Plan ==\r\n_1: string\r\nProject [_1#420]\r\n+- SerializeFromObject [staticinvoke(class org.apache.spark.unsafe.types.UTF8String, StringType, fromString, input[0, scala.Tuple2]._1, true) AS _1#420,input[0, scala.Tuple2]._2 AS _2#421]\r\n   +- Filter <function1>.apply\r\n      +- DeserializeToObject newInstance(class scala.Tuple2), obj#419: scala.Tuple2\r\n         +- LocalRelation [_1#416,_2#417], [[0,1800000001,1,61],[0,1800000001,2,62],[0,1800000001,3,63]]\r\n\r\n== Optimized Logical Plan ==\r\nProject [_1#416]\r\n+- Filter <function1>.apply\r\n   +- LocalRelation [_1#416,_2#417], [[0,1800000001,1,61],[0,1800000001,2,62],[0,1800000001,3,63]]\r\n```\r\n\r\n## How was this patch tested?\r\n\r\nExisting tests and I added a test to check if `filter and then select` works.\r\n","created_at":"2016-05-13T09:01:21Z","updated_at":"2016-05-13T09:05:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f4da99b70c4967bb0f31d25d674aeb443aaacac3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/13096/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/13096/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/13096/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/2620409239e808578dbbd9e0099d32f041879f8e","head":{"label":"ueshin:issues/SPARK-15313","ref":"issues/SPARK-15313","sha":"2620409239e808578dbbd9e0099d32f041879f8e","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":"2015-12-26T13:14:03Z","pushed_at":"2016-05-13T08:52:36Z","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":180545,"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":"c74a6c3f2363f065a4915fdadec5eff665fa02e7","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-05-13T08:28:01Z","pushed_at":"2016-05-13T09:01:22Z","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":492439,"stargazers_count":8498,"watchers_count":8498,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":7892,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":397,"forks":7892,"open_issues":397,"watchers":8498,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/13096"},"html":{"href":"https://github.com/apache/spark/pull/13096"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/13096"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/13096/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/13096/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/13096/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/2620409239e808578dbbd9e0099d32f041879f8e"}}}}