Exception while using hyperLogLog field in postAggregation in druid

hello,
I’m using a hyperLogLog field in an arithmetic operation defined as postAggregation in druid groupBy query. But it’s raising an exception as

"{“error”: “HTTP Error 500: Internal Server Error \n Druid Error: io.druid.query.aggregation.hyperloglog.HLLCV1 cannot be cast to java.lang.Number }”.

I’m
not getting why is this exception getting raised. hyperLogLog field returns me proper result when used isolated.

Can anyone tell me how to resolve this exception?

Thanks,
Rajnandini

I think you haven’t wrapped your hyperunique aggregator properly in the post aggregator. It should be something like this:

“postAggregations” : [{

“type” : “arithmetic”,

“name” :“example_pa”,

“fn” : “+”,

“fields”: [

{ “type” : “hyperUniqueCardinality”, “name”: “pa1”, “fieldName” : “my_hyperunique_aggregator” },

{ “type” : “constant”, “name”: “pa2”, “value” : 1000 }]

}]

Thank you. This helped. But I have a query that can I use a post aggregated metric in some new post aggregation as a part of fieldaccess ? Means post aggregation on previously defined post aggregation metric. Is it possible?

Thank you,
Rajnandini

Yes you can!

Extending the example above, we have added 1000 to the hyperUnique count, then in the second post aggregator we multiply by 10. I’ve included the nested and referred versions. The referred version is a forced example, but if you wanted the query to output the intermediate step (the +1000 in this case) you’d use that…

Nested:

‘postAggregations’:

[{

‘fn’: ‘*’,

‘name’: ‘result’,

‘type’: ‘arithmetic’}

‘fields’: [

{ ‘name’: ‘const’, ‘type’: ‘constant’, ‘value’: 10},

{

‘fn’: ‘+’,

‘name’: ‘ts1addconst’,

‘type’: ‘arithmetic’}

‘fields’: [

{‘fieldName’: ‘my_hyperunique_aggregator’, ‘type’: ‘hyperUniqueCardinality’},

{‘name’: ‘const’, ‘type’: ‘constant’, ‘value’: 1000}

],

],

]

Referred:

“postAggregations” : [{

“type” : “arithmetic”,

“name” :“example_pa”,

“fn” : “+”,

“fields”: [

{ “type” : “hyperUniqueCardinality”, “name”: “pa1”, “fieldName” : “my_hyperunique_aggregator” },

{ “type” : “constant”, “name”: “pa2”, “value” : 1000 }]

},

{

“type”: “arithmetic”,

“name”: “example_pa2”,

“fn”: “*”,

“fields”: [

{ “type”: “fieldAccess”, “name”: “prev_pa”, “fieldName”: “example_pa”},

{ “type”: “fieldAccess”, “name”: “const”, “value”: 10}

]

}

]

Thanks a lot

-Rajnandini