Aggregations return null when filter condition does not match

Hi,

I see that if no record matches a filter condition, the aggregation returns null. Shouldn’t 0 be returned as the response? Or is that something handled in the new versions of druid?

I think you’re looking for this

https://github.com/apache/druid/issues/4349

Hi, thanks for your reply. But that issue points to how null or empty value of a dimensions should be handled. But what I am trying to understand is that let’s say I have a metric called “pageviews” and I want to know how many pageviews came from country “India”. Then if I apply a filter “country” = “India”, Should I get the response as pageviews = 0 or pageviews = null ?

Hi Abhishek,

Are you using a filtered aggregator ? You might be running into this issue : https://github.com/apache/druid/issues/6089

Hi,

I am not using a filtered aggregator. I am specifying filter separately and aggregations separately. But I am still facing the issue.

{

“queryType”:“timeseries”,

“intervals”:[

“2020-03-02T00:00:00Z/2020-03-03T00:00:00Z”

],

“granularity”:“day”,

“dataSource”:“my_datasource”,

“filter”:{

“type”:“and”,

“fields”:[

{

“type”:“selector”,

“value”:“val1”,

“dimension”:“dim1”

},

{

“type”:“selector”,

“value”:“val2”,

“dimension”:“dim2”

}

]

},

“aggregations”:[

{

“fieldName”:“pageviews”,

“name”:“pageviews”,

“type”:“longSum”

}

]

}

``

Hi Abhishek,

In a timeseries query, you can skip empty buckets by adding the following to your query. So, for the days that don’t have data where the filter matches, they’ll be omitted from the results:

“context”: {“skipEmptyBuckets”: “true”}

Hope that helps as a quick-fix.

Hi Abhishek,

Should have asked you, what version of Druid are you on ?

I tried this query on latest version 0.17.0, and it returns 0 instead of null,

{
“queryType”: “timeseries”,
“dataSource”: {
“type”: “table”,
“name”: “wikipedia_no_rollup”
},
“dimension”: {
“type”: “default”,
“dimension”: “cityName”,
“outputName”: “city”,
“outputType”: “STRING”
},
“metric”: {
“type”: “numeric”,
“metric”: “deleted”
},
“threshold”: 100,
“intervals”: {
“type”: “intervals”,
“intervals”: [
“-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z”
]
},
“filter”: {
“type”: “selector”,
“dimension”: “cityName”,
“value”: “Rome”
},
“granularity”: {
“type”: “all”
},
“aggregations”: [
{
“type”: “longSum”,
“name”: “deleted”,
“fieldName”: “deleted”
}
]
}

We have 2 versions running at present in different environments.

Running it in 0.9 gives 0

Running it in 0.12 gives null

And that is what I didn’t understand. Why in the new version it is coming as null ?

There is a property called druid.generic.useDefaultValueForNull. Maybe I have to set it but not sure where.

Yeah, when druid.generic.useDefaultValueForNull

is set to true, the result should be zero, and if it’s set to false, the result should be null. But the default is true, so I think you should get zero.

Where is this property set?

You can add it to your common.runtime.properties