7

I am trying to convert the following druid sql query to a druid json query, as one of the columns i have is a multi-value dimension for which druid does not support a sql style query.

My sql query:

SELECT date_dt, source, type_labels, COUNT(DISTINCT unique_p_hll)
  FROM "test"
WHERE 
  type_labels = 'z' AND
  (a_id IN ('a', 'b', 'c') OR b_id IN ('m', 'n', 'p'))
GROUP BY date_dt, source, type_labels;

unique_p_hll is an hll column with uniques.

The druid json query i came up with is following:

{
  "queryType": "groupBy",
  "dataSource": "test",
  "granularity": "day",
  "dimensions": ["source", "type_labels"],
  "limitSpec": {},
  "filter": {
    "type": "and",
    "fields": [
      { "type": "selector", "dimension": "type_labels", "value": "z" },   
      { "type": "or", "fields": [
        { "type": "in", "dimension": "a_id", "values": ["a", "b", "c"] },
        { "type": "in", "dimension": "b_id", "values": ["m", "n", "p"] }
      ]}
    ]
  },
  "aggregations": [
    { "type": "longSum", "name": "unique_p_hll", "fieldName": "p_id" }
  ],
  "intervals": [ "2018-08-01/2018-08-02" ]
}

But the json query seems to be returning empty resultset. I can see the output correctly in Pivot UI. Though the array column type_labels values show up as {"array_element": "z"} instead of simply "z".

Pratik Khadloya
  • 12,509
  • 11
  • 81
  • 106

1 Answers1

0

Does the query return empty string, or does it return a formatted JSON with zero records?

If the former, I can suggest a couple of leads for debugging this issue:

  1. Make sure that the query is properly sent to the Broker, as shown in Druid's query tutorial:

curl -X 'POST' -H 'Content-Type:application/json' -d @query-file.json http://<BROKER-IP>:<BROKER-PORT>/druid/v2?pretty

  1. Also, check the Broker's log for errors.
yurmix
  • 852
  • 2
  • 8
  • 21