How to use limitSpec to order a metric in GroupBy query?

Hi,

I’m using the groupby query for the first time. I would like to group by two dimensions and order by one metric:

data:

timestamp | dimension1 | dimension2 | metric 1 | metric 2

Hi Juan,

Have you had a chance to read these docs?

http://druid.io/docs/latest/querying/groupbyquery.html

http://druid.io/docs/latest/querying/limitspec.html

Inline with more thoughts.

Hi,

I’m using the groupby query for the first time. I would like to group by two dimensions and order by one metric:

data:

timestamp | dimension1 | dimension2 | metric 1 | metric 2


2000-01-01T00:00:00.000Z | name A | name B | 1 | 3

2000-01-01T00:00:00.000Z | name A | name B | 5 | 4

2000-01-01T00:00:00.000Z | name A | name C | 8 | 3

2000-01-01T00:00:00.000Z | name A | name C | 2 | 6

the query is the following but I don’t know how to specify limitSpec to reach the results ordered by metric 1:

{

“queryType”: “groupBy”,

“dataSource”: “nameData”,

“granularity”: “all”,

“dimensions”: [“dimension1”, “dimension2”],

“limitSpec”: { “dimension” : “metric 1”, “direction” : “descending”},

“aggregations”: [

{ “type”: “count”, “name”: “count” },

{ “type”: “longSum”, “name”: “metric1”, “fieldName”: “metric1” },

{ “type”: “longSum”, “name”: “metric2”, “fieldName”: “metric1”}

],

“intervals”: [ “2000-01-01T00:00:00.000/2050-01-03T00:00:00.000” ]

}

I’ve read about “OrderByColumnSpec” but I don’t know if it has to be indicated inside of the limitSpec or it’is another field.

It is inside the “columns” field of the limitSpec.

Hi Fangjin,

Yes I had! I’ve read both documents, but I needed your inline comments to join where place “OrderByColumnSpec” inside of “limitSpec”.

In any case, it’s running :slight_smile:

On the other hand I think that after "“columns” field should not finish with comma.

{
    "type"    : "default",
    "limit"   : <integer_value>,
    "columns" : [list of OrderByColumnSpec],
}

Thank you very much!

Juan

Additionally,

I paste the solution that will be able to be useful for another beginner:

“limitSpec”: {

“type” : “default”,

“columns” : [{

“dimension” : “metric1”,

“direction” : “descending”

} ]

},

Hi Juan, do you mind contributing a fix and more concrete examples here?

https://github.com/druid-io/druid/blob/master/docs/content/querying/limitspec.md

It’ll help others in the future. Glad to hear the query is running.