In the Edit Dimension dialog, from the Type drop-down list, select Time to specify a time-based dimension.
With a time-based dimension, a new window is managed and evaluated based on the time a tuple arrives. For example, a tuple containing the aggregate results may be emitted, and the current window closed, when a tuple arrives outside the period allowed for the currently open window. The triggering tuple is received by a new window.
Using a time-based dimension can cause unnecessary waits in testing or operation, makes impossible any deterministic tuple-by-tuple playback in unit tests and feed simulations, and complicates high availability design patterns.
In general, TIBCO recommends avoiding the use of the time-based dimension for most applications. Instead, use a field-based
dimension with a timestamp field, or a predicate dimension with an expression such as
lastval( to create a 30-second window.
time_field) - firstval(
time_field) > seconds(30)
The Edit Dimension dialog for a field-based dimension has the following appearance.
The following example clarifies the behavior of the time-based dimension option:
An aggregate is set with the dimension for window opening and closing to 60 seconds (Advance 60, Close and Emit 60), with no intermediate output.
Because there must always be an open window to receive tuples, this dimension's window opens when the first tuple arrives (call this time 0).
Subsequent tuples arrive at 3, 8, 17, 31, 42, 49, and 58 seconds.
At time 60 seconds, the window emits an aggregate tuple and closes with a
A tuple arrives at time 62 seconds. A new window with its
firstvalset to 60 opens to receive it.
The following describes the options available in the Edit Dimension dialog for time-based dimensions.
|Category||Options and Meaning|
|Opening policy||Select one of these options:
|Window size||Select one of these options:
|Emission policy||Select one of these options:
|Optional windows||Select one of these options:
To learn more about field-based aggregation works, run the Aggregate Operator Time Dimension Sample. It contains an Aggregate operator that uses 2-second windows to compute average price per share of stocks, grouped by the Symbol field. The following table shows output from the sample. The output fields are:
Symbol — The stock symbol, used to sort tuples into groups
Average — Time-based Average price per share, calculated with the aggregate function avg()
start_time — The time the window opened (its
end_time — The time the window closed (its
first_time — Time at which the first tuple arrived in the window (
last_time — Time at which the last tuple arrived in the window (
n — The number of tuples over which average price per share was computed (
Each table row is one window's emission when it closed. Timestamps have been truncated to only show hours, minutes, and seconds.
When you run the sample with input from the feed simulation resource
AggregateByTime.sbfs, you will find that averages, first and last times, and number of tuples per window all vary, depending on the rate of input.