{"action":"created","issue":{"url":"https://api.github.com/repos/apache/spark/issues/13906","repository_url":"https://api.github.com/repos/apache/spark","labels_url":"https://api.github.com/repos/apache/spark/issues/13906/labels{/name}","comments_url":"https://api.github.com/repos/apache/spark/issues/13906/comments","events_url":"https://api.github.com/repos/apache/spark/issues/13906/events","html_url":"https://github.com/apache/spark/pull/13906","id":162299646,"number":13906,"title":"[SPARK-16208][SQL] Add `PropagateEmptyRelation` optimizer","user":{"login":"dongjoon-hyun","id":9700541,"avatar_url":"https://avatars.githubusercontent.com/u/9700541?v=3","gravatar_id":"","url":"https://api.github.com/users/dongjoon-hyun","html_url":"https://github.com/dongjoon-hyun","followers_url":"https://api.github.com/users/dongjoon-hyun/followers","following_url":"https://api.github.com/users/dongjoon-hyun/following{/other_user}","gists_url":"https://api.github.com/users/dongjoon-hyun/gists{/gist_id}","starred_url":"https://api.github.com/users/dongjoon-hyun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dongjoon-hyun/subscriptions","organizations_url":"https://api.github.com/users/dongjoon-hyun/orgs","repos_url":"https://api.github.com/users/dongjoon-hyun/repos","events_url":"https://api.github.com/users/dongjoon-hyun/events{/privacy}","received_events_url":"https://api.github.com/users/dongjoon-hyun/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":34,"created_at":"2016-06-25T21:07:15Z","updated_at":"2016-07-01T01:28:11Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/13906","html_url":"https://github.com/apache/spark/pull/13906","diff_url":"https://github.com/apache/spark/pull/13906.diff","patch_url":"https://github.com/apache/spark/pull/13906.patch"},"body":"## What changes were proposed in this pull request?\r\n\r\nThis PR adds a new logical optimizer, `PropagateEmptyRelation`, to collapse a logical plans consisting of only empty LocalRelations.\r\n\r\n**Optimizer Targets**\r\n\r\n1. Binary(or Higher)-node Logical Plans\r\n   - Union with all empty children.\r\n   - Join with one or two empty children (including Intersect/Except).\r\n2. Unary-node Logical Plans\r\n   - Project/Filter/Sample/Join/Limit/Repartition with all empty children.\r\n   - Aggregate with all empty children and without AggregateFunction expressions, COUNT.\r\n   - Generate with Explode because other UserDefinedGenerators like Hive UDTF returns results.\r\n\r\n**Sample Query**\r\n```sql\r\nWITH t1 AS (SELECT a FROM VALUES 1 t(a)),\r\n     t2 AS (SELECT b FROM VALUES 1 t(b) WHERE 1=2)\r\nSELECT a,b\r\nFROM t1, t2\r\nWHERE a=b\r\nGROUP BY a,b\r\nHAVING a>1\r\nORDER BY a,b\r\n```\r\n\r\n**Before**\r\n```scala\r\nscala> sql(\"with t1 as (select a from values 1 t(a)), t2 as (select b from values 1 t(b) where 1=2) select a,b from t1, t2 where a=b group by a,b having a>1 order by a,b\").explain\r\n== Physical Plan ==\r\n*Sort [a#0 ASC, b#1 ASC], true, 0\r\n+- Exchange rangepartitioning(a#0 ASC, b#1 ASC, 200)\r\n   +- *HashAggregate(keys=[a#0, b#1], functions=[])\r\n      +- Exchange hashpartitioning(a#0, b#1, 200)\r\n         +- *HashAggregate(keys=[a#0, b#1], functions=[])\r\n            +- *BroadcastHashJoin [a#0], [b#1], Inner, BuildRight\r\n               :- *Filter (isnotnull(a#0) && (a#0 > 1))\r\n               :  +- LocalTableScan [a#0]\r\n               +- BroadcastExchange HashedRelationBroadcastMode(List(cast(input[0, int, false] as bigint)))\r\n                  +- *Filter (isnotnull(b#1) && (b#1 > 1))\r\n                     +- LocalTableScan <empty>, [b#1]\r\n```\r\n\r\n**After**\r\n```scala\r\nscala> sql(\"with t1 as (select a from values 1 t(a)), t2 as (select b from values 1 t(b) where 1=2) select a,b from t1, t2 where a=b group by a,b having a>1 order by a,b\").explain\r\n== Physical Plan ==\r\nLocalTableScan <empty>, [a#0, b#1]\r\n```\r\n\r\n## How was this patch tested?\r\n\r\nPass the Jenkins tests (including a new testsuite)."},"comment":{"url":"https://api.github.com/repos/apache/spark/issues/comments/229832429","html_url":"https://github.com/apache/spark/pull/13906#issuecomment-229832429","issue_url":"https://api.github.com/repos/apache/spark/issues/13906","id":229832429,"user":{"login":"AmplabJenkins","id":4031291,"avatar_url":"https://avatars.githubusercontent.com/u/4031291?v=3","gravatar_id":"","url":"https://api.github.com/users/AmplabJenkins","html_url":"https://github.com/AmplabJenkins","followers_url":"https://api.github.com/users/AmplabJenkins/followers","following_url":"https://api.github.com/users/AmplabJenkins/following{/other_user}","gists_url":"https://api.github.com/users/AmplabJenkins/gists{/gist_id}","starred_url":"https://api.github.com/users/AmplabJenkins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AmplabJenkins/subscriptions","organizations_url":"https://api.github.com/users/AmplabJenkins/orgs","repos_url":"https://api.github.com/users/AmplabJenkins/repos","events_url":"https://api.github.com/users/AmplabJenkins/events{/privacy}","received_events_url":"https://api.github.com/users/AmplabJenkins/received_events","type":"User","site_admin":false},"created_at":"2016-07-01T01:28:11Z","updated_at":"2016-07-01T01:28:11Z","body":"Test PASSed.\nRefer to this link for build results (access rights to CI server needed): \nhttps://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/61581/\nTest PASSed."}}
{"actor":{"display_login":"AmplabJenkins"}}