druid icon indicating copy to clipboard operation
druid copied to clipboard

limitSpec behavior

Open guobingkun opened this issue 11 years ago • 4 comments

It's unclear from the documentation how limitSpec is applied. From my observation, "orderBy" in limitSpec is applied on each granularity bucket while "limit" is applied on the overall result, which is kinda wired.

Example:

{"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}
{"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}
{"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}
{"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}
{"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}

Query:

{
    "queryType":"groupBy",
    "dataSource":"wikipedia_index_test",
    "granularity":"day",
    "dimensions":[
        "page"
    ],
    "limitSpec":{"type":"default", "limit": 5, "columns":[{"dimension":"delta", "direction":"descending"}]},
    "aggregations":[
        {
            "type":"count",
            "name":"rows"
        },
        {
            "type":"longSum",
            "fieldName":"delta",
            "name":"delta"
        }
    ],
    "intervals":[
        "2013-08-31T00:00/2013-09-02T00:00"
    ]
}

Result:

[ {
  "version" : "v1",
  "timestamp" : "2013-08-31T00:00:00.000Z",
  "event" : {
    "delta" : 330,
    "page" : "Striker Eureka",
    "rows" : 1
  }
}, {
  "version" : "v1",
  "timestamp" : "2013-08-31T00:00:00.000Z",
  "event" : {
    "delta" : -143,
    "page" : "Gypsy Danger",
    "rows" : 1
  }
}, {
  "version" : "v1",
  "timestamp" : "2013-09-01T00:00:00.000Z",
  "event" : {
    "delta" : 900,
    "page" : "Crimson Typhoon",
    "rows" : 1
  }
}, {
  "version" : "v1",
  "timestamp" : "2013-09-01T00:00:00.000Z",
  "event" : {
    "delta" : 111,
    "page" : "Cherno Alpha",
    "rows" : 1
  }
}, {
  "version" : "v1",
  "timestamp" : "2013-09-01T00:00:00.000Z",
  "event" : {
    "delta" : -9,
    "page" : "Coyote Tango",
    "rows" : 1
  }
} ]

If I change limit to 3, then only 3 entries will be returned,

[ {
  "version" : "v1",
  "timestamp" : "2013-08-31T00:00:00.000Z",
  "event" : {
    "delta" : 330,
    "page" : "Striker Eureka",
    "rows" : 1
  }
}, {
  "version" : "v1",
  "timestamp" : "2013-08-31T00:00:00.000Z",
  "event" : {
    "delta" : -143,
    "page" : "Gypsy Danger",
    "rows" : 1
  }
}, {
  "version" : "v1",
  "timestamp" : "2013-09-01T00:00:00.000Z",
  "event" : {
    "delta" : 900,
    "page" : "Crimson Typhoon",
    "rows" : 1
  }
} ]

guobingkun avatar Sep 28 '15 15:09 guobingkun

I also think it's a bit weird but probably too late to change. I would be OK with documenting it and possibly adding a flag to have different behavior.

What would actually make sense though?

  1. Sort and limit both in granular buckets
  2. Sort and limit both globally
  3. Sort in granular buckets, limit globally (current behavior)

I always thought of "granularity" as meaning "do the same basic query on each granular bucket" so from that perspective (1) makes sense. But (2) is possibly more useful? I dunno.

gianm avatar Sep 29 '15 01:09 gianm

I think (3) can be achieve by (1) with a shortened interval? I know there are people who are asking for (1), and I also think (2) is useful since it mimics SQL semantics. Maybe adding a flag to switch between (1) and (2)?

guobingkun avatar Sep 29 '15 15:09 guobingkun

This issue has been marked as stale due to 280 days of inactivity. It will be closed in 2 weeks if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the [email protected] list. Thank you for your contributions.

stale[bot] avatar Jun 21 '19 18:06 stale[bot]

This issue has been closed due to lack of activity. If you think that is incorrect, or the issue requires additional review, you can revive the issue at any time.

stale[bot] avatar Jul 05 '19 19:07 stale[bot]