Skip to content

Tumbling-count-window

The tumbling-count-window creates a-per-worker tumbling count window. In this implementation a window aggregate is stored only in the machine's memory. The aggregate is emitted to configured sink via a emit point.

Based on VoltAggregateBuilder each event is transformed into a request. Lastly a key can be provided so incoming event is routed to the right local window and aggregated.

Note that the window is a local, per-worker keyed aggregate, not a machine-wide keyed aggregate.

In case of downstream system error this tumbling-count-window will re-process events.

stream
  .aggregateWithWindow(Windows.<Event>tumblingCountWindow()
      .withMaxEventsPerWindow(500)
      .withKeyExtractor(Event::getUserId)
      .withAggregateDefinition(builder -> builder
          .count()
          .sum("amount", Event::getAmount)
          .min("amount", Event::getAmount)
          .max("amount", Event::getAmount)
          .distinct("id", (EventToStringExtractor<Event>) Event::getId)
      )
      .withExceptionHandler((records, context, throwable) -> {
          // handle error
      })
  )
  .emit(TumblingWindowTrigger.atEndOfWindow)
  ...
emitter:
  tumbling-count-window:
    maxEventsPerWindow: 500
    keyExtractor: "com.example.Event::getUserId"
    aggregateDefinition:
      from: "com.example.Event"
      builder:
        - type: count
        - type: sum (amount)
        - type: min (amount)
        - type: max (amount)
        - type: distinct (id)
  triggers:
    - trigger: atEndOfWindow
      ...

Java dependency management

Add this declaration to your dependency management system to access the configuration DSL for this plugin in Java.

<dependency>
    <groupId>org.voltdb</groupId>
    <artifactId>volt-stream-plugin-window-api</artifactId>
    <version>1.7.1</version>
</dependency>
implementation group: 'org.voltdb', name: 'volt-stream-plugin-window-api', version: '1.7.1'

Properties

maxEventsPerWindow

Defines how many events this window can accumulate before it gets closed. Must be greater than 0 Type: number

keyExtractor

The key is optional, if set the window will aggregate only events with the same key value. The key has to conform to Java equal and hashCode contract. Type: object

aggregateDefinition

The aggregate is defined by the provided builder Required.

Type: object

exceptionHandler

Custom exception handler enabling interception of all errors related to this emitter. Type: object

Available Triggers

atEndOfWindow

Triggered after window has been closed.

atEventAggregate

Triggered after each event has been aggregated. An emitted aggregate is a snapshot of the aggregate after the event has been applied.

atAggregateError

Triggered every time the aggregate fails with an error and an event has not been aggregated.

JSON Schema

You can validate or explore the configuration using its JSON Schema.