How to sort data across segments


Unable to sort data using the below query:


“queryType”: “select”,

“dataSource”: “RAN_NodeB_Hourly”,

“granularity”: “all”,

“limitSpec”: {“type”:“default”,“columns”:[

{“dimension”: “NodeB_P_3”, “direction”: “DESCENDING”,“dimensionOrder”:“alphanumeric”},

{“dimension”: “NodeB_P_4”, “direction”: “DESCENDING”,“dimensionOrder”:“alphanumeric”}


“intervals”: [ “2018-12-05T05:00:00.000Z/2018-12-05T05:59:00.000Z” ],







“type”: “selector”,

“dimension”: “COUNTER_GROUP_ID”,

“value”: “NodeB_CG_1”




“pagingSpec”: {


“threshold”: 10000



Hey Amit,

Select/Scan queries don’t support sorting, so you’re best off with groupBy. It aggregates and sorts at the same time.

Thanks Gian,
Can we query on druid using SQL queries,

If yes then, can we do it directly or do we need to put hive or some other application in between.



Got the answer thanks

Hey Amit,

Druid SQL exists and it is documented here: However, it is basically a planning layer on top of native Druid queries, so it can only do things that native Druid queries can do.

I tried below query for sorting , but the sorting is taking place inside segments, how can we do the sorting across the segments:

      "queryType": “groupBy",
      "dataSource": "RAN_NodeB_Hourly",
      "granularity": "all",
      "limitSpec": {"type":"default","columns":[
        {"dimension": "NodeB_P_3", "direction": "DESCENDING","dimensionOrder":"alphanumeric"},
        {"dimension": "NodeB_P_4", "direction": "DESCENDING","dimensionOrder":"alphanumeric"}
      "intervals": [ "2018-12-05T05:00:00.000Z/2018-12-05T05:59:00.000Z" ],
            "type": "selector",
            "dimension": "COUNTER_GROUP_ID",
            "value": "NodeB_CG_1"
      "pagingSpec": {
        "threshold": 10000