1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
|
# UDAF
> The functions for aggregate processors.
## Function of content
- [Collect List](#Collect-List)
- [Collect Set](#Collect-Set)
- [First Value](#First-Value)
- [Last Value](#Last-Value)
- [Long Count](#Long-Count)
- [Max](#Max)
- [MEAN](#Mean)
- [Min](#Min)
- [Number SUM](#Number-SUM)
- [HLLD](#HLLD)
- [Approx Count Distinct HLLD](#Approx-Count-Distinct-HLLD)
- [HDR Histogram](#HDR-Histogram)
- [Approx Quantile HDR](#APPROX_QUANTILE_HDR)
- [Approx Quantiles HDR](#APPROX_QUANTILES_HDR)
## Description
UDF(User Defined Aggregate Function) is used to extend the functions of aggregate processor. It is a part of the processing pipeline. It can be used in the pre-processing, processing, and post-processing pipeline. Each processor can assemble UDAFs into a pipeline. Within the pipeline, events are processed by each Function in order, top‑>down.
The deference between UDF and UDAF is:
- UDF is used to process each event, and the output is also an event. UDAF is used to process a group of events, and the output is also an event.
- A UDF is designed to perform a transformation or calculation on a single event. A UDAF is designed to perform an aggregation over a group of events, such as summing values, calculating an average, or finding a maximum. It processes multiple events of input data and produces a single aggregated result.
## UDAF Definition
The UDAF basic properties are the same as UDF, such as `name`, `event`, `context`,more detail can be found in [UDF](udf.md). But Aggregate Processor have some methods to process the data is:
- `void add()`: Add a new event to the aggregation.
- `void getResult()`: Get the result of the aggregation.
## Functions
### Collect List
COLLECT_LIST is used to collect the value of the field in the group of events.
```COLLECT_LIST(filter, lookup_fields, output_fields)```
- filter: optional
- lookup_fields: required. Now only support one field.
- output_fields: optional. If not set, the output field name is `lookup_field_name`.
- parameters: optional.
- collect_type: `<String>` optional. input field type can be `array` or `object`. Default is `object`. If set to array, the function processes each element of the array individually.If set to object, the function treats the entire input object as a single element.
Example:
```yaml
- function: COLLECT_LIST
lookup_fields: [client_ip]
output_fields: [client_ip_list]
- parameters:
- collect_type: object
```
### Collect Set
COLLECT_SET is used to collect the unique value of the field in the group of events.
```COLLECT_SET(filter, lookup_fields, output_fields)```
- filter: optional
- lookup_fields: required. Now only support one field.
- output_fields: optional. If not set, the output field name is `lookup_field_name`.
- parameters: optional.
- collect_type: `<String>` optional. input field type can be `array` or `object`. Default is `object`. If set to array, the function expands the elements of the array and removes duplicates.If set to object, the function treats the entire input object as a single element and removes duplicates.
Example
```yaml
- function: COLLECT_SET
lookup_fields: [client_ip]
output_fields: [client_ip_set]
- parameters:
- collect_type: array
```
### First Value
FIRST_VALUE is used to get the first value of the field in the group of events.
```FIRST_VALUE(filter, lookup_fields, output_fields)```
- filter: optional
- lookup_fields: required. Now only support one field.
- output_fields: optional. If not set, the output field name is `lookup_field_name`.
Example
```yaml
- function: FIRST_VALUE
lookup_fields: [client_ip]
output_fields: [first_client_ip]
```
### Last Value
LAST_VALUE is used to get the last value of the field in the group of events.
```LAST_VALUE(filter, lookup_fields, output_fields)```
- filter: optional
- lookup_fields: required. Now only support one field.
- output_fields: optional. If not set, the output field name is `lookup_field_name`.
Example
```yaml
- function: LAST_VALUE
lookup_fields: [client_ip]
output_fields: [last_client_ip]
```
### Long Count
LONG_COUNT is used to count the number of events in the group of events.
```LONG_COUNT(filter, lookup_fields, output_fields)```
- filter: optional
- lookup_fields: optional.
- output_fields: required.
Example
```yaml
- function: LONG_COUNT
output_fields: [sessions]
```
### Max
MAX is used to get the maximum value of the field in the group of events.
```MAX(filter, lookup_fields, output_fields)```
- filter: optional
- lookup_fields: required. Now only support one field.
- output_fields: optional. If not set, the output field name is `lookup_field_name`.
Example
```yaml
- function: MAX
lookup_fields: [receive_time]
output_fields: [receive_time]
```
### Mean
MEAN is used to calculate the mean value of the field in the group of events. The lookup field value must be a number.
```MEAN(filter, lookup_fields, output_fields[, parameters])```
- filter: optional
- lookup_fields: required. Now only support one field.
- output_fields: optional. If not set, the output field name is `lookup_field_name`.
- parameters: optional.
- precision: `<Integer>` required. The precision of the mean value. Default is 2.
Example
```yaml
- function: MEAN
lookup_fields: [received_bytes]
output_fields: [received_bytes_mean]
```
### Min
MIN is used to get the minimum value of the field in the group of events.
```MIN(filter, lookup_fields, output_fields)```
- filter: optional
- lookup_fields: required. Now only support one field.
- output_fields: optional. If not set, the output field name is `lookup_field_name`.
Example
```yaml
- function: MIN
lookup_fields: [receive_time]
output_fields: [receive_time]
```
### Number SUM
NUMBER_SUM is used to sum the value of the field in the group of events. The lookup field value must be a number.
```NUMBER_SUM(filter, lookup_fields, output_fields)```
- filter: optional
- lookup_fields: required. Now only support one field.
- output_fields: optional. If not set, the output field name is `lookup_field_name`.
Example
```yaml
- function: NUMBER_SUM
lookup_fields: [received_bytes]
output_fields: [received_bytes_sum]
```
### HLLD
hlld is a high-performance C server which is used to expose HyperLogLog sets and operations over them to networked clients. More details can be found in [hlld](https://github.com/armon/hlld).
```HLLD(filter, lookup_fields, output_fields[, parameters])```
- filter: optional
- lookup_fields: required.
- output_fields: required.
- parameters: optional.
- input_type: `<String>` optional. input field type can be `regular` or `sketch`. Default is `sketch`. regular field data type includes `string`, `int`, `long`, `float`, `double` etc.
- precision: `<Integer>` optional. The precision of the hlld value. Default is 12.
- output_format: `<String>` optional. The output format can be either `base64(encoded string)` or `binary(byte[])`. The default is `base64`.
Example
Merge multiple string field into a HyperLogLog data structure.
```yaml
- function: HLLD
lookup_fields: [client_ip]
output_fields: [client_ip_hlld]
parameters:
input_type: regular
```
Merge multiple `unique_count ` metric type fields into a HyperLogLog data structure
```yaml
- function: HLLD
lookup_fields: [client_ip_hlld]
output_fields: [client_ip_hlld]
parameters:
input_type: sketch
```
### Approx Count Distinct HLLD
Approx Count Distinct HLLD is used to count the approximate number of distinct values in the group of events.
```APPROX_COUNT_DISTINCT_HLLD(filter, lookup_fields, output_fields[, parameters])```
- filter: optional
- lookup_fields: required.
- output_fields: required.
- parameters: optional.
- input_type: `<String>` optional. Refer to `HLLD` function.
- precision: `<Integer>` optional. Refer to `HLLD` function.
Example
```yaml
- function: APPROX_COUNT_DISTINCT_HLLD
lookup_fields: [client_ip]
output_fields: [unique_client_ip]
parameters:
input_type: regular
```
```yaml
- function: APPROX_COUNT_DISTINCT_HLLD
lookup_fields: [client_ip_hlld]
output_fields: [unique_client_ip]
parameters:
input_type: sketch
```
### HDR Histogram
A High Dynamic Range (HDR) Histogram. More details can be found in [HDR Histogram](https://github.com/HdrHistogram/HdrHistogram).
```HDR_HISTOGRAM(filter, lookup_fields, output_fields[, parameters])```
- filter: optional
- lookup_fields: required.
- output_fields: required.
- parameters: optional.
- input_type: `<String>` optional. input field type can be `regular` or `sketch`. Default is `sketch`. regular field is a number.
- lowestDiscernibleValue: `<Integer>` optional. The lowest trackable value. Default is 1.
- highestTrackableValue: `<Integer>` optional. The highest trackable value. Default is 2.
- numberOfSignificantValueDigits: `<Integer>` optional. The number of significant value digits. Default is 1. The range is 1 to 5.
- autoResize: `<Boolean>` optional. If true, the highestTrackableValue will auto-resize. Default is true.
- output_format: `<String>` optional. The output format can be either `base64(encoded string)` or `binary(byte[])`. The default is `base64`.
Example
```yaml
- function: HDR_HISTOGRAM
lookup_fields: [latency_ms]
output_fields: [latency_ms_histogram]
parameters:
input_type: regular
lowestDiscernibleValue: 1
highestTrackableValue: 3600000
numberOfSignificantValueDigits: 3
```
```yaml
- function: HDR_HISTOGRAM
lookup_fields: [latency_ms_histogram]
output_fields: [latency_ms_histogram]
parameters:
input_type: sketch
```
### Approx Quantile HDR
Approx Quantile HDR is used to calculate the approximate quantile value of the field in the group of events.
```APPROX_QUANTILE_HDR(filter, lookup_fields, output_fields, quantile[, parameters])```
- filter: optional
- lookup_fields: required.
- output_fields: required.
- parameters: optional.
- input_type: `<String>` optional. Refer to `HDR_HISTOGRAM` function.
- lowestDiscernibleValue: `<Integer>` optional. Refer to `HDR_HISTOGRAM` function.
- highestTrackableValue: `<Integer>` required. Refer to `HDR_HISTOGRAM` function.
- numberOfSignificantValueDigits: `<Integer>` optional. Refer to `HDR_HISTOGRAM` function.
- autoResize: `<Boolean>` optional. Refer to `HDR_HISTOGRAM` function.
- probability: `<Double>` optional. The probability of the quantile. Default is 0.5.
Example
```yaml
- function: APPROX_QUANTILE_HDR
lookup_fields: [latency_ms]
output_fields: [latency_ms_p95]
parameters:
input_type: regular
probability: 0.95
```
```yaml
- function: APPROX_QUANTILE_HDR
lookup_fields: [latency_ms_HDR]
output_fields: [latency_ms_p95]
parameters:
input_type: sketch
probability: 0.95
```
### Approx Quantiles HDR
Approx Quantiles HDR is used to calculate the approximate quantile values of the field in the group of events.
```APPROX_QUANTILES_HDR(filter, lookup_fields, output_fields, quantiles[, parameters])```
- filter: optional
- lookup_fields: required.
- output_fields: required.
- parameters: optional.
- input_type: `<String>` optional. Refer to `HDR_HISTOGRAM` function.
- lowestDiscernibleValue: `<Integer>` optional. Refer to `HDR_HISTOGRAM` function.
- highestTrackableValue: `<Integer>` required. Refer to `HDR_HISTOGRAM` function.
- numberOfSignificantValueDigits: `<Integer>` optional. Refer to `HDR_HISTOGRAM` function.
- autoResize: `<Boolean>` optional. Refer to `HDR_HISTOGRAM` function.
- probabilities: `<Array<Double>>` required. The list of probabilities of the quantiles. Range is 0 to 1.
Example
```yaml
- function: APPROX_QUANTILES_HDR
lookup_fields: [latency_ms]
output_fields: [latency_ms_quantiles]
parameters:
input_type: regular
probabilities: [0.5, 0.95, 0.99]
```
```yaml
- function: APPROX_QUANTILES_HDR
lookup_fields: [latency_ms_HDR]
output_fields: [latency_ms_quantiles]
parameters:
input_type: sketch
probabilities: [0.5, 0.95, 0.99]
```
|