{"action":"created","issue":{"url":"https://api.github.com/repos/apache/spark/issues/11846","repository_url":"https://api.github.com/repos/apache/spark","labels_url":"https://api.github.com/repos/apache/spark/issues/11846/labels{/name}","comments_url":"https://api.github.com/repos/apache/spark/issues/11846/comments","events_url":"https://api.github.com/repos/apache/spark/issues/11846/events","html_url":"https://github.com/apache/spark/pull/11846","id":142127563,"number":11846,"title":"[SPARK-13957] [SQL] Support Group By Ordinal in SQL","user":{"login":"gatorsmile","id":11567269,"avatar_url":"https://avatars.githubusercontent.com/u/11567269?v=3","gravatar_id":"","url":"https://api.github.com/users/gatorsmile","html_url":"https://github.com/gatorsmile","followers_url":"https://api.github.com/users/gatorsmile/followers","following_url":"https://api.github.com/users/gatorsmile/following{/other_user}","gists_url":"https://api.github.com/users/gatorsmile/gists{/gist_id}","starred_url":"https://api.github.com/users/gatorsmile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gatorsmile/subscriptions","organizations_url":"https://api.github.com/users/gatorsmile/orgs","repos_url":"https://api.github.com/users/gatorsmile/repos","events_url":"https://api.github.com/users/gatorsmile/events{/privacy}","received_events_url":"https://api.github.com/users/gatorsmile/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":14,"created_at":"2016-03-20T04:19:21Z","updated_at":"2016-03-24T23:57:27Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/11846","html_url":"https://github.com/apache/spark/pull/11846","diff_url":"https://github.com/apache/spark/pull/11846.diff","patch_url":"https://github.com/apache/spark/pull/11846.patch"},"body":"#### What changes were proposed in this pull request?\r\nThis PR is to support group by position in SQL. For example, when users input the following query\r\n```SQL\r\nselect c1 as a, c2, c3, sum(*) from tbl group by 1, 3, c4\r\n```\r\nThe ordinals are recognized as the positions in the select list. Thus, `Analyzer` converts it to \r\n```SQL\r\nselect c1, c2, c3, sum(*) from tbl group by c1, c3, c4\r\n```\r\n\r\nThis is controlled by the config option `spark.sql.groupByOrdinal`.\r\n- When true, the ordinal numbers in group by clauses are treated as the position in the select list.\r\n- When false, the ordinal numbers are ignored.\r\n- Only convert integer literals (not foldable expressions). If found foldable expressions, ignore them. \r\n- When the positions specified in the group by clauses correspond to the aggregate functions in select list, output an exception message.\r\n- star is not allowed to use in the select list when users specify ordinals in group by\r\n\r\nNote: This PR is taken from https://github.com/apache/spark/pull/10731. When merging this PR, please give the credit to @zhichao-li\r\n\r\nAlso cc all the people who are involved in the previous discussion:  @rxin @cloud-fan @marmbrus @yhuai @hvanhovell @adrian-wang @chenghao-intel @tejasapatil\r\n\r\n#### How was this patch tested?\r\n\r\nAdded a few test cases for both positive and negative test cases.\r\n"},"comment":{"url":"https://api.github.com/repos/apache/spark/issues/comments/201077355","html_url":"https://github.com/apache/spark/pull/11846#issuecomment-201077355","issue_url":"https://api.github.com/repos/apache/spark/issues/11846","id":201077355,"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-03-24T23:57:27Z","updated_at":"2016-03-24T23:57:27Z","body":"Merged build finished. Test PASSed."}}