Image Modified
Script Aggregator provides a flexible and controlled way to correlate, consolidate and aggregate records of different data types. It is used to perform more advanced and complex operations that cannot be solved using pre-defined operations in Data Aggregator.
As a user, you can use Script Aggregator to
- perform correlation: To aggregate usage data with nested data object across multiple sources.
- perform advanced aggregation: To aggregate usage data with nested data object.
push partially: To send data to the downstream function during aggregation based on a certain condition.
Info |
---|
|
To be able to use full potential of this function, you must be well versed with JavaScript. |
...
Object name | Description | Properties | Methods |
---|
Session | The session object represents the current matching aggregated data. | session.key : The id of the session constructed based on the group by rules.- session.data: The configurable data block of the session used for storing the aggregated data. The default value is { }.
session.met a: Meta data collected by the application containing:count : Number of records matching the current session. The count is increased for every time a record passes. firstEvent : Timestamp when the first record matched the session.lastEvent : Timestamp when the latest record matched the session.flushType : The flushType is set as part of the meta downstream once the session is either pushed or flushed.
mycustomProperty : Allows to add a custom property in the meta data, that will also be pushed downstream along with the payload.
Info |
---|
expanded | true |
---|
icon | false |
---|
title | Meta properties |
---|
|
Code Block |
---|
meta = {
count: number,
firstEvent: timestamp,
lastEvent: timestamp,
flushType: string,
myCustomProperty: any,
} |
|
session.timeoutAt : Timestamp when a session should be flushed. Use the methods setTimeout and clearTimeout when configuring the timeoutAt property.
| Push: Pushes the session downstream along with its current meta. If excludeCurrentPayload is set to true the pushed session will exclude the current input as part of the meta. By default, excludeCurrentPayload is false. The flushType argument sets the flushType property on the meta. Defaults to PUSH.
Code Block |
---|
| await session.push(
excludeCurrentPayload?: boolean, flushType?: string
) |
Expand |
---|
|
Code Block |
---|
if (!session.data.myCounter) {
session.data.myCounter = 0;
}
session.data.myCounter += 1;
await session.push();
/*
## 1 ##
OUTPUT:
payload -> { myCounter: 1 }
meta -> {
count: 1,
firstEvent: '2022-06-10T08:57:06.242Z',
lastEvent: '2022-06-10T08:57:06.242Z'
}
SESSION in store: {
data: {
myCounter: 1,
}
meta: {
count: 1,
firstEvent: '2022-06-10T08:57:06.242Z',
lastEvent: '2022-06-10T08:57:06.242Z'
}
}
## 2 ##
OUTPUT:
payload -> { myCounter: 2 }
meta -> {
count: 2,
firstEvent: '2022-06-10T08:57:06.242Z',
lastEvent: '2022-06-10T08:57:06.553Z'
}
SESSION in store: {
data: {
myCounter: 2,
}
meta: {
count: 2,
firstEvent: '2022-06-10T08:57:06.242Z',
lastEvent: '2022-06-10T08:57:06.553Z'
}
}
*\
|
|
delete : Deletes the current session. You will not be able to perform any operation on the session object after it has been deleted.
Code Block |
---|
| await session.delete();
// Will not push!
await session.push();
// Will not be saved!
session.data.myProperty = 1337; |
flush(excludeCurrentPayload?: boolean) : Flushes the data and deletes the session. You will not be able to perform any operation on the session object after it has been deleted.
Note |
---|
| Flush does not happen automatically. You need to flush the session in the configuration. So it is recommended to keep flush in the On Timeout block.
In case of batch stream, On Timeout is triggered for timedout sessions when the stream is run. And, in case of real-time streams, the On Timeout is triggered for timed out sessions every 60 seconds. |
If excludeCurrentPayload is set as true , the flushed session will exclude the current input as part of the meta. excludeCurrentPayload defaults to false. The flushType argument sets the flushType property on the meta. Defaults to FLUSH.
Code Block |
---|
| await session.flush(
excludeCurrentPayload?: boolean, flushType?: string
) |
clear(): Clears the session and can be re-used.
Code Block |
---|
await session.clear() |
s etTimeout : A timeout can be set to trigger delayed actions. Setting a timeout on a session sets or updates the current timeout in milliseconds. The value can either be in UTC date format or string format.
Expand |
---|
|
Code Block |
---|
session.setTimeout(new Date('2022-06-10T08:57:06.242Z'));
const moment = require('moment');
session.setTimeout(moment().add(1, 'days').toDate()); |
|
- clearTimeout: Clears the timeout previously established by calling
setTimeout .
|
...