Aggregation Methods

The Script Aggregator function inherits all functions and variables from the Script function and also has an object of its own called session, which is a representation of a group of data records matching the configured conditions.

You can use the following properties/objects when configuring aggregation with the session object:

Properties

Methods

Properties

Methods

  • 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.meta: Meta data collected by the application containing:

    • count: Number of records matching the current session. The count is increased every time a  record passes. 

    • firstEvent: Timestamp for when the first record matched the session.

    • lastEvent: Timestamp for when the last 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 you to add a custom property in the meta data, that will also be pushed downstream along with the payload.

      Meta properties

      meta = { count: number, firstEvent: timestamp, lastEvent: timestamp, flushType: string, myCustomProperty: any, }
  • session.timeoutAt: Timestamp for 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 data.
    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. 

Syntax

await session.push( excludeCurrentPayload?: boolean, flushType?: string )
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.

    Syntax

  • 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 have to add it in your JavaScript configuration. It is recommended to keep flush in the On Timeout block.

If you have a batch stream, On Timeout is triggered for sessions that have timed out when the stream is executed. If you have a real-time stream, the On Timeout is triggered for sessions that have timed out every 60 seconds.

If excludeCurrentPayload is set as true, the flushed session will exclude the current input as part of the meta data. excludeCurrentPayload is set to false by default. The flushType argument defines the flushType property for the meta data and is set to flush by default.

Syntax

  • clear(): Clears the session but it is not deleted and can still be used and viewed in the Aggregation management.

  • setTimeout: 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.



  • clearTimeout: Clears the timeout previously set by calling setTimeout.

Â