{"action":"created","issue":{"url":"https://api.github.com/repos/druid-io/druid/issues/1780","labels_url":"https://api.github.com/repos/druid-io/druid/issues/1780/labels{/name}","comments_url":"https://api.github.com/repos/druid-io/druid/issues/1780/comments","events_url":"https://api.github.com/repos/druid-io/druid/issues/1780/events","html_url":"https://github.com/druid-io/druid/issues/1780","id":108685403,"number":1780,"title":"limitSpec behavior","user":{"login":"guobingkun","id":11789051,"avatar_url":"https://avatars.githubusercontent.com/u/11789051?v=3","gravatar_id":"","url":"https://api.github.com/users/guobingkun","html_url":"https://github.com/guobingkun","followers_url":"https://api.github.com/users/guobingkun/followers","following_url":"https://api.github.com/users/guobingkun/following{/other_user}","gists_url":"https://api.github.com/users/guobingkun/gists{/gist_id}","starred_url":"https://api.github.com/users/guobingkun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guobingkun/subscriptions","organizations_url":"https://api.github.com/users/guobingkun/orgs","repos_url":"https://api.github.com/users/guobingkun/repos","events_url":"https://api.github.com/users/guobingkun/events{/privacy}","received_events_url":"https://api.github.com/users/guobingkun/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-09-28T15:38:22Z","updated_at":"2015-09-29T15:40:21Z","closed_at":null,"body":"It's unclear from the documentation how limitSpec is applied. \r\nFrom my observation, \"orderBy\" in limitSpec is applied on each granularity bucket while \"limit\" is applied on the overall result, which is kinda wired.\r\n\r\nExample:\r\n```\r\n{\"timestamp\": \"2013-08-31T01:02:33Z\", \"page\": \"Gypsy Danger\", \"language\" : \"en\", \"user\" : \"nuclear\", \"unpatrolled\" : \"true\", \"newPage\" : \"true\", \"robot\": \"false\", \"anonymous\": \"false\", \"namespace\":\"article\", \"continent\":\"North America\", \"country\":\"United States\", \"region\":\"Bay Area\", \"city\":\"San Francisco\", \"added\": 57, \"deleted\": 200, \"delta\": -143}\r\n{\"timestamp\": \"2013-08-31T03:32:45Z\", \"page\": \"Striker Eureka\", \"language\" : \"en\", \"user\" : \"speed\", \"unpatrolled\" : \"false\", \"newPage\" : \"true\", \"robot\": \"true\", \"anonymous\": \"false\", \"namespace\":\"wikipedia\", \"continent\":\"Australia\", \"country\":\"Australia\", \"region\":\"Cantebury\", \"city\":\"Syndey\", \"added\": 459, \"deleted\": 129, \"delta\": 330}\r\n{\"timestamp\": \"2013-09-01T07:11:21Z\", \"page\": \"Cherno Alpha\", \"language\" : \"ru\", \"user\" : \"masterYi\", \"unpatrolled\" : \"false\", \"newPage\" : \"true\", \"robot\": \"true\", \"anonymous\": \"false\", \"namespace\":\"article\", \"continent\":\"Asia\", \"country\":\"Russia\", \"region\":\"Oblast\", \"city\":\"Moscow\", \"added\": 123, \"deleted\": 12, \"delta\": 111}\r\n{\"timestamp\": \"2013-09-01T11:58:39Z\", \"page\": \"Crimson Typhoon\", \"language\" : \"zh\", \"user\" : \"triplets\", \"unpatrolled\" : \"true\", \"newPage\" : \"false\", \"robot\": \"true\", \"anonymous\": \"false\", \"namespace\":\"wikipedia\", \"continent\":\"Asia\", \"country\":\"China\", \"region\":\"Shanxi\", \"city\":\"Taiyuan\", \"added\": 905, \"deleted\": 5, \"delta\": 900}\r\n{\"timestamp\": \"2013-09-01T12:41:27Z\", \"page\": \"Coyote Tango\", \"language\" : \"ja\", \"user\" : \"stringer\", \"unpatrolled\" : \"true\", \"newPage\" : \"false\", \"robot\": \"true\", \"anonymous\": \"false\", \"namespace\":\"wikipedia\", \"continent\":\"Asia\", \"country\":\"Japan\", \"region\":\"Kanto\", \"city\":\"Tokyo\", \"added\": 1, \"deleted\": 10, \"delta\": -9}\r\n```\r\n\r\nQuery:\r\n```\r\n{\r\n    \"queryType\":\"groupBy\",\r\n    \"dataSource\":\"wikipedia_index_test\",\r\n    \"granularity\":\"day\",\r\n    \"dimensions\":[\r\n        \"page\"\r\n    ],\r\n    \"limitSpec\":{\"type\":\"default\", \"limit\": 5, \"columns\":[{\"dimension\":\"delta\", \"direction\":\"descending\"}]},\r\n    \"aggregations\":[\r\n        {\r\n            \"type\":\"count\",\r\n            \"name\":\"rows\"\r\n        },\r\n        {\r\n            \"type\":\"longSum\",\r\n            \"fieldName\":\"delta\",\r\n            \"name\":\"delta\"\r\n        }\r\n    ],\r\n    \"intervals\":[\r\n        \"2013-08-31T00:00/2013-09-02T00:00\"\r\n    ]\r\n}\r\n```\r\n\r\nResult:\r\n```\r\n[ {\r\n  \"version\" : \"v1\",\r\n  \"timestamp\" : \"2013-08-31T00:00:00.000Z\",\r\n  \"event\" : {\r\n    \"delta\" : 330,\r\n    \"page\" : \"Striker Eureka\",\r\n    \"rows\" : 1\r\n  }\r\n}, {\r\n  \"version\" : \"v1\",\r\n  \"timestamp\" : \"2013-08-31T00:00:00.000Z\",\r\n  \"event\" : {\r\n    \"delta\" : -143,\r\n    \"page\" : \"Gypsy Danger\",\r\n    \"rows\" : 1\r\n  }\r\n}, {\r\n  \"version\" : \"v1\",\r\n  \"timestamp\" : \"2013-09-01T00:00:00.000Z\",\r\n  \"event\" : {\r\n    \"delta\" : 900,\r\n    \"page\" : \"Crimson Typhoon\",\r\n    \"rows\" : 1\r\n  }\r\n}, {\r\n  \"version\" : \"v1\",\r\n  \"timestamp\" : \"2013-09-01T00:00:00.000Z\",\r\n  \"event\" : {\r\n    \"delta\" : 111,\r\n    \"page\" : \"Cherno Alpha\",\r\n    \"rows\" : 1\r\n  }\r\n}, {\r\n  \"version\" : \"v1\",\r\n  \"timestamp\" : \"2013-09-01T00:00:00.000Z\",\r\n  \"event\" : {\r\n    \"delta\" : -9,\r\n    \"page\" : \"Coyote Tango\",\r\n    \"rows\" : 1\r\n  }\r\n} ]\r\n```\r\n\r\nIf I change limit to 3, then only 3 entries will be returned,\r\n\r\n```\r\n[ {\r\n  \"version\" : \"v1\",\r\n  \"timestamp\" : \"2013-08-31T00:00:00.000Z\",\r\n  \"event\" : {\r\n    \"delta\" : 330,\r\n    \"page\" : \"Striker Eureka\",\r\n    \"rows\" : 1\r\n  }\r\n}, {\r\n  \"version\" : \"v1\",\r\n  \"timestamp\" : \"2013-08-31T00:00:00.000Z\",\r\n  \"event\" : {\r\n    \"delta\" : -143,\r\n    \"page\" : \"Gypsy Danger\",\r\n    \"rows\" : 1\r\n  }\r\n}, {\r\n  \"version\" : \"v1\",\r\n  \"timestamp\" : \"2013-09-01T00:00:00.000Z\",\r\n  \"event\" : {\r\n    \"delta\" : 900,\r\n    \"page\" : \"Crimson Typhoon\",\r\n    \"rows\" : 1\r\n  }\r\n} ]\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/druid-io/druid/issues/comments/144097602","html_url":"https://github.com/druid-io/druid/issues/1780#issuecomment-144097602","issue_url":"https://api.github.com/repos/druid-io/druid/issues/1780","id":144097602,"user":{"login":"guobingkun","id":11789051,"avatar_url":"https://avatars.githubusercontent.com/u/11789051?v=3","gravatar_id":"","url":"https://api.github.com/users/guobingkun","html_url":"https://github.com/guobingkun","followers_url":"https://api.github.com/users/guobingkun/followers","following_url":"https://api.github.com/users/guobingkun/following{/other_user}","gists_url":"https://api.github.com/users/guobingkun/gists{/gist_id}","starred_url":"https://api.github.com/users/guobingkun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guobingkun/subscriptions","organizations_url":"https://api.github.com/users/guobingkun/orgs","repos_url":"https://api.github.com/users/guobingkun/repos","events_url":"https://api.github.com/users/guobingkun/events{/privacy}","received_events_url":"https://api.github.com/users/guobingkun/received_events","type":"User","site_admin":false},"created_at":"2015-09-29T15:40:21Z","updated_at":"2015-09-29T15:40:21Z","body":"I think (3) can be achieve by (1) with a shortened interval? \r\nI know there are people who are asking for (1), and I also think (2) is also useful since it mimics SQL semantics. Maybe adding a flag to switch between (1) and (2)?\r\n"}}