{"action":"created","issue":{"url":"https://api.github.com/repos/apache/spark/issues/12421","repository_url":"https://api.github.com/repos/apache/spark","labels_url":"https://api.github.com/repos/apache/spark/issues/12421/labels{/name}","comments_url":"https://api.github.com/repos/apache/spark/issues/12421/comments","events_url":"https://api.github.com/repos/apache/spark/issues/12421/events","html_url":"https://github.com/apache/spark/pull/12421","id":148726882,"number":12421,"title":"[SPARK-14664][SQL] Fix DecimalAggregates optimizer not to break Window queries","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,"milestone":null,"comments":7,"created_at":"2016-04-15T18:02:18Z","updated_at":"2016-04-22T00:38:55Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/12421","html_url":"https://github.com/apache/spark/pull/12421","diff_url":"https://github.com/apache/spark/pull/12421.diff","patch_url":"https://github.com/apache/spark/pull/12421.patch"},"body":"## What changes were proposed in this pull request?\r\n\r\nHistorically, `DecimalAggregates` optimizer is designed to transform general `sum/avg(decimal)`.\r\nHowever, it breaks recently added windows queries like the followings. The following queries work well without this optimizer.\r\n\r\n**Sum**\r\n```scala\r\nscala> sql(\"select sum(a) over () from (select explode(array(1.0,2.0)) a) t\").head\r\njava.lang.RuntimeException: Unsupported window function: MakeDecimal((sum(UnscaledValue(a#31)),mode=Complete,isDistinct=false),12,1)\r\n```\r\n\r\n**Average**\r\n```scala\r\nscala> sql(\"select avg(a) over () from (select explode(array(1.0,2.0)) a) t\").head\r\njava.lang.RuntimeException: Unsupported window function: cast(((avg(UnscaledValue(a#40)),mode=Complete,isDistinct=false) / 10.0) as decimal(6,5))\r\n```\r\n\r\nThis PR aims to fix `DecimalAggregates` optimizer not to handle aggregation queries over windows.\r\nNote that this PR does not aim to implement optimization over Window aggregation.\r\n\r\n## How was this patch tested?\r\n\r\nPass the Jenkins tests (with newly added testcases)\r\n"},"comment":{"url":"https://api.github.com/repos/apache/spark/issues/comments/213181115","html_url":"https://github.com/apache/spark/pull/12421#issuecomment-213181115","issue_url":"https://api.github.com/repos/apache/spark/issues/12421","id":213181115,"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-04-22T00:38:55Z","updated_at":"2016-04-22T00:38:55Z","body":"Merged build finished. Test PASSed."}}