yuanlihan opened a new issue #11387:
URL: https://github.com/apache/druid/issues/11387


   ### Motivation
   The current moving average extension provides some common as well as useful 
functions. Although the extension is named as moving average, it's not limited 
to an average and can be extended to moving/trailing aggregates. And it'll be 
useful we can use existing Druid aggregators to support different 
moving/trailing aggregates.
   
   ### Proposed changes
   
   Add a `default` type `Averager` to support general trailing aggregates using 
existing Druid aggregators.
   
   Query syntax:
   
   ```json
   {
       "queryType": "movingAverage",
       "dataSource": "wikipedia",
       "granularity": {
           "type": "period",
           "period": "PT1H"
       },
       "dimensions": [],
       "intervals": [
           "2016-06-27T08:00:00.000Z/2016-06-27T11:00:00.000Z"
       ],
       "aggregations": [
           {
               "name": "deltaHourChanges",
               "fieldName": "delta",
               "type": "longSum"
           },
           {
               "type": "cardinality",
               "name": "deltaHourUniqueUsers",
               "fields": [
                   "user"
               ],
               "round": true
           }
       ],
       "averagers": [
           {
               "name": "trailing7HourChangesSum",
               "fieldName": "deltaHourChanges",
               "type": "default",
               "buckets": 7
           },
           {
               "name": "trailing7HourUniqueUsers",
               "fieldName": "deltaHourUniqueUsers",
               "type": "default",
               "buckets": 7
           }
       ]
   }
   ```
   
   Result:
   
   ```json
   [
       {
           "version": "v1",
           "timestamp": "2016-06-27T08:00:00.000Z",
           "event": {
               "deltaHourChanges": 459861,
               "deltaHourUniqueUsers": 492,
               "trailing7HourUniqueUsers": 2249,
               "trailing7HourChangesSum": 3200366
           }
       },
       {
           "version": "v1",
           "timestamp": "2016-06-27T09:00:00.000Z",
           "event": {
               "deltaHourChanges": 526043,
               "deltaHourUniqueUsers": 527,
               "trailing7HourUniqueUsers": 2385,
               "trailing7HourChangesSum": 3390380
           }
       },
       {
           "version": "v1",
           "timestamp": "2016-06-27T10:00:00.000Z",
           "event": {
               "deltaHourChanges": 501710,
               "deltaHourUniqueUsers": 609,
               "trailing7HourUniqueUsers": 2587,
               "trailing7HourChangesSum": 3502582
           }
       }
   ]
   ```
   
   ### Rationale
   
   The `default` type `Averager` will use the same aggregator of its dependent 
aggregation field to do trailing aggregate. We can support many different type 
of trailing aggregates by leveraging existing Druid aggregators.
   
   ### Operational impact
   
   User can use the `default` type `Averager` to do corresponding trailing 
aggregates like using Druid aggregators.
   
   ### Test plan (optional)
   
   I add unit tests to meet code coverage rate and test in test cluster.
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to