{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/43716232","id":43716232,"diff_hunk":"@@ -166,26 +166,68 @@ abstract class Star extends LeafExpression with NamedExpression {\n  * Represents all of the input attributes to a given relational operator, for example in\n  * \"SELECT * FROM ...\".\n  *\n- * @param table an optional table that should be the target of the expansion.  If omitted all\n- *              tables' columns are produced.\n+ * This is also used to expand structs. For example:\n+ * \"SELECT record.* from (SELECT struct(a,b,c) as record ...)\n+ *\n+ * @param target an optional name that should be the target of the expansion.  If omitted all\n+ *              targets' columns are produced. This can either be a table name or struct name. This\n+ *              is a list of identifiers that is the path of the expansion.\n  */\n-case class UnresolvedStar(table: Option[String]) extends Star with Unevaluable {\n+case class UnresolvedStar(target: Option[Seq[String]]) extends Star with Unevaluable {\n+\n+  override def expand(input: LogicalPlan, resolver: Resolver): Seq[NamedExpression] = {\n \n-  override def expand(input: Seq[Attribute], resolver: Resolver): Seq[NamedExpression] = {\n-    val expandedAttributes: Seq[Attribute] = table match {\n+    // First try to expand assuming it is table.*.\n+    val expandedAttributes: Seq[Attribute] = target match {\n       // If there is no table specified, use all input attributes.\n-      case None => input\n+      case None => input.output\n       // If there is a table, pick out attributes that are part of this table.\n-      case Some(t) => input.filter(_.qualifiers.filter(resolver(_, t)).nonEmpty)\n+      case Some(t) => if (t.size == 1) {\n+        input.output.filter(_.qualifiers.filter(resolver(_, t.head)).nonEmpty)\n+      } else {\n+        List()\n+      }\n     }\n-    expandedAttributes.zip(input).map {\n-      case (n: NamedExpression, _) => n\n-      case (e, originalAttribute) =>\n-        Alias(e, originalAttribute.name)(qualifiers = originalAttribute.qualifiers)\n+    if (!expandedAttributes.isEmpty) {\n+      if (expandedAttributes.forall(_.isInstanceOf[NamedExpression])) {\n+        return expandedAttributes\n+      } else {\n+        require(expandedAttributes.size == input.output.size)\n+        expandedAttributes.zip(input.output).map {\n+          case (e, originalAttribute) =>\n+            Alias(e, originalAttribute.name)(qualifiers = originalAttribute.qualifiers)\n+        }","path":"sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/unresolved.scala","position":71,"original_position":71,"commit_id":"886acc7ba1dc95348117b5890ce8115efa149b0b","original_commit_id":"886acc7ba1dc95348117b5890ce8115efa149b0b","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":"`Attribute` is always `NamedExpression`, I don't think we will hit this branch.","created_at":"2015-11-03T04:58:16Z","updated_at":"2015-11-03T04:58:16Z","html_url":"https://github.com/apache/spark/pull/9343#discussion_r43716232","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/9343","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/43716232"},"html":{"href":"https://github.com/apache/spark/pull/9343#discussion_r43716232"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/9343"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/9343","id":49081604,"html_url":"https://github.com/apache/spark/pull/9343","diff_url":"https://github.com/apache/spark/pull/9343.diff","patch_url":"https://github.com/apache/spark/pull/9343.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/9343","number":9343,"state":"closed","locked":false,"title":"[SPARK-11329] [SQL] Support star expansion for structs.","user":{"login":"nongli","id":242468,"avatar_url":"https://avatars.githubusercontent.com/u/242468?v=3","gravatar_id":"","url":"https://api.github.com/users/nongli","html_url":"https://github.com/nongli","followers_url":"https://api.github.com/users/nongli/followers","following_url":"https://api.github.com/users/nongli/following{/other_user}","gists_url":"https://api.github.com/users/nongli/gists{/gist_id}","starred_url":"https://api.github.com/users/nongli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nongli/subscriptions","organizations_url":"https://api.github.com/users/nongli/orgs","repos_url":"https://api.github.com/users/nongli/repos","events_url":"https://api.github.com/users/nongli/events{/privacy}","received_events_url":"https://api.github.com/users/nongli/received_events","type":"User","site_admin":false},"body":"1. Supporting expanding structs in Projections. i.e.\r\n  \"SELECT s.*\" where s is a struct type.\r\n  This is fixed by allowing the expand function to handle structs in addition to tables.\r\n\r\n2. Supporting expanding * inside aggregate functions of structs.\r\n   \"SELECT max(struct(col1, structCol.*))\"\r\n   This requires recursively expanding the expressions. In this case, it it the aggregate\r\n   expression \"max(...)\" and we need to recursively expand its children inputs.","created_at":"2015-10-28T23:31:44Z","updated_at":"2015-11-03T04:58:16Z","closed_at":"2015-11-03T04:33:38Z","merged_at":null,"merge_commit_sha":"a9bc75993d23ee95d1d476e2e073fbec99d0971a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/9343/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/9343/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/9343/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/886acc7ba1dc95348117b5890ce8115efa149b0b","head":{"label":"nongli:spark-11329","ref":"spark-11329","sha":"886acc7ba1dc95348117b5890ce8115efa149b0b","user":{"login":"nongli","id":242468,"avatar_url":"https://avatars.githubusercontent.com/u/242468?v=3","gravatar_id":"","url":"https://api.github.com/users/nongli","html_url":"https://github.com/nongli","followers_url":"https://api.github.com/users/nongli/followers","following_url":"https://api.github.com/users/nongli/following{/other_user}","gists_url":"https://api.github.com/users/nongli/gists{/gist_id}","starred_url":"https://api.github.com/users/nongli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nongli/subscriptions","organizations_url":"https://api.github.com/users/nongli/orgs","repos_url":"https://api.github.com/users/nongli/repos","events_url":"https://api.github.com/users/nongli/events{/privacy}","received_events_url":"https://api.github.com/users/nongli/received_events","type":"User","site_admin":false},"repo":{"id":30051398,"name":"spark","full_name":"nongli/spark","owner":{"login":"nongli","id":242468,"avatar_url":"https://avatars.githubusercontent.com/u/242468?v=3","gravatar_id":"","url":"https://api.github.com/users/nongli","html_url":"https://github.com/nongli","followers_url":"https://api.github.com/users/nongli/followers","following_url":"https://api.github.com/users/nongli/following{/other_user}","gists_url":"https://api.github.com/users/nongli/gists{/gist_id}","starred_url":"https://api.github.com/users/nongli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nongli/subscriptions","organizations_url":"https://api.github.com/users/nongli/orgs","repos_url":"https://api.github.com/users/nongli/repos","events_url":"https://api.github.com/users/nongli/events{/privacy}","received_events_url":"https://api.github.com/users/nongli/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/nongli/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/nongli/spark","forks_url":"https://api.github.com/repos/nongli/spark/forks","keys_url":"https://api.github.com/repos/nongli/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nongli/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nongli/spark/teams","hooks_url":"https://api.github.com/repos/nongli/spark/hooks","issue_events_url":"https://api.github.com/repos/nongli/spark/issues/events{/number}","events_url":"https://api.github.com/repos/nongli/spark/events","assignees_url":"https://api.github.com/repos/nongli/spark/assignees{/user}","branches_url":"https://api.github.com/repos/nongli/spark/branches{/branch}","tags_url":"https://api.github.com/repos/nongli/spark/tags","blobs_url":"https://api.github.com/repos/nongli/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nongli/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nongli/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/nongli/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nongli/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/nongli/spark/languages","stargazers_url":"https://api.github.com/repos/nongli/spark/stargazers","contributors_url":"https://api.github.com/repos/nongli/spark/contributors","subscribers_url":"https://api.github.com/repos/nongli/spark/subscribers","subscription_url":"https://api.github.com/repos/nongli/spark/subscription","commits_url":"https://api.github.com/repos/nongli/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/nongli/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/nongli/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/nongli/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/nongli/spark/contents/{+path}","compare_url":"https://api.github.com/repos/nongli/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nongli/spark/merges","archive_url":"https://api.github.com/repos/nongli/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nongli/spark/downloads","issues_url":"https://api.github.com/repos/nongli/spark/issues{/number}","pulls_url":"https://api.github.com/repos/nongli/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/nongli/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/nongli/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nongli/spark/labels{/name}","releases_url":"https://api.github.com/repos/nongli/spark/releases{/id}","created_at":"2015-01-30T02:01:12Z","updated_at":"2015-01-30T02:01:28Z","pushed_at":"2015-11-03T01:34:46Z","git_url":"git://github.com/nongli/spark.git","ssh_url":"git@github.com:nongli/spark.git","clone_url":"https://github.com/nongli/spark.git","svn_url":"https://github.com/nongli/spark","homepage":null,"size":123641,"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":"476f4348e2ea57ea05f4b470abfe76d97eeb20ce","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}","created_at":"2014-02-25T08:00:08Z","updated_at":"2015-11-03T00:14:04Z","pushed_at":"2015-11-03T04:43:51Z","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":1651451,"stargazers_count":5986,"watchers_count":5986,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5579,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":375,"forks":5579,"open_issues":375,"watchers":5986,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/9343"},"html":{"href":"https://github.com/apache/spark/pull/9343"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/9343"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/9343/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/9343/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/9343/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/886acc7ba1dc95348117b5890ce8115efa149b0b"}}}}