Javascript aggregator to get Max value

Hi Druid Gurus,

i am trying to use javascript aggregator to find max value in a dimension(possible values or ‘Y’ or 'N) but below druid query always returns 0.0. I am not sure where i am going wrong. Can you please help me on this?

– Sql to be accomplished

select

seller,

buyer,

max(flag_y_N)

from dataSource

where seller = ‘1111’

and calendar_dt between ‘2016-09-01’ and ‘2016-09-04’

group by seller,buyer

– Druid Query

{

“queryType”: “groupBy”,

“dataSource”: “Source”,

“granularity”: “all”,

“dimensions”: [

“seller”,

“buyer”

],

“filter”: {

“type”: “and”,

“fields”: [{

“type”: “selector”,

“dimension”: “seller”,

“value”: “1111”

}, {

“type”: “javascript”,

“dimension”: “calendar_dt”,

“function”: “function(x) {return ( x >= ‘2016-09-01’ && x<= ‘2016-09-04’)}”

}]

},

“aggregations”: [

{

“type”: “javascript”,

“fieldNames”: [“flag_y_n”],

“name”: “value_y_n”,

“fnAggregate”: “function(current,a) { return a}”,

“fnCombine” : “function(partialA, partialB) { if (Math.max(partialA,partialB) == ‘Y’) { return 1;} else {return 0;} }”,

“fnReset” : “function() {return 0; }”

}

],

“intervals”: [

“2016-09-01/2016-09-04”

]

}

Actually i was able to figure this out

i changed the spec as below

“fnAggregate”: “function(current,a) { if (a == ‘Y’) { return 1 ;} else {return 0;}}”,

“fnCombine”: “function(partialA, partialB) { return Math.max(partialA,partialB)}”,

“fnReset”: “function() {return 0; }”

You may also be interested in: https://github.com/druid-io/druid/pull/3226