javascript - Counting transitions (rising edges) of boolean metric in Druid query -
i'm getting feet wet nosql queries , druid , came across interesting query case i'm not sure how solve.
how write druid timeseries query count rising-edge transitions granularity of 1 second?
two issues i'm aware of:
- aggregations stateless. have input of
current
floating point aggregation value, , can return updated floating point aggregation value. see "javascript aggregator" in druid aggregation docs - queries aware of current
segment
, must have separate aggregations formula on different segments. see "sharding-the-data" in druid docs.
simplified data looks like:
seconds metric 0.0 0 0.3 1 0.6 1 1.0 1 1.3 1 1.6 0 2.0 1 2.3 0 2.6 1 3.0 0 3.3 0
desired output:
seconds rising-edge-count 0.0 1 1.0 0 2.0 2 3.0 0
here's best shot using floating point's negativity store previous-value's state, it's super hacky , doesn't seem give desired result...
{ "querytype": "timeseries", "datasource": "data-store", "granularity": "hour", "intervals": ["2015-01-01/2019-01-01"], "filter": { "type": "in", "dimension": "switchx", "values": ["0","1"] }, "aggregations": [ { "type": "javascript", "name": "rising-edge", "fieldnames" : ["switchx"], "fnaggregate" : "function(current, a) { return (1 - 2*a) * (math.abs(current) + (a > (current<0))); }", "fncombine" : "function(partiala, partialb) { return partiala + partialb; }", "fnreset" : "function() { return 0; }" } ] }
Comments
Post a Comment