10.8.3 How to adjust the time

The timestamp adjustment function uses the following procedure to adjust time information in tuples:

  1. Sets the timestamp
    The function timestamps a tuple that has arrived at the SDP server. To do this, it first discards from the time value set in the records in the tuple any portion of the time value that is smaller than the specified unit of time. It then sets the resulting value as the timestamp for the tuple. For example, if sec is specified as the unit of time, any value smaller than a second, such as a milliseconds value, is discarded from the time value and the resulting value (in seconds) is set as the timestamp.
  2. Holds tuples
    The function holds tuples whose timestamp falls within the range of times to be adjusted.
    It also discards any tuple whose timestamp is earlier than the range of times to be adjusted.
  3. Inputs tuples to the input stream
    Those tuples among the tuples that are being held that are now outside the range of times to be adjusted because of a change in the range are input to the input stream.

When the timestamp adjustment function holds tuples and inputs them to the input stream, the method used to adjust the tuples' time information and the order in which tuples are input to the input stream depend on the reference time, the time set in the records in the tuples, and the specified unit of time. This subsection discusses how to adjust a tuple's time and the order in which tuples are input to the input stream.

Organization of this subsection
(1) How to adjust a tuple's time
(2) Order in which tuples are input to the input stream

(1) How to adjust a tuple's time

This subsection describes how to adjust a tuple's time in the following four cases:

Tuple is first tuple obtained after a query group has started
The time set in records in the tuple that was sent from the input adaptor is set as the reference time.
The figure below shows an example of the first tuple obtained after a query group has started. In this example, sec is specified for the unit of time and 2 is specified for the length of time to be adjusted.

Figure 10-27 Example of the first tuple obtained after a query group has started

[Figure]
When the first tuple (with 09:00:01:015 set as the time in the records) is sent from the input adaptor, the timestamp adjustment function sets the reference time to 09:00:01.
In this case, the time adjustment range is 09:00:01-08:59:59. This first tuple is held in the timestamp adjustment function as a tuple with the timestamp 09:00:01.
Time set in records in the tuple is after (subsequent to) the current reference time
If the time set in records in the tuple is after the current reference time, the tuple's time is adjusted with the following procedure:
  1. The new reference time is set based on the time information in the records in the tuple that has been sent. As a result, the range of times to be adjusted changes.
    This tuple is held in the timestamp adjustment function.
  2. If there are tuples that are being held by the timestamp adjustment function because their time was within the range of times to be adjusted based on the previous reference time, but their time is no longer within the range of times to be adjusted because of the change to the new reference time, those tuples are input to the input stream in chronological order of their timestamps. If multiple of these tuples have the same timestamp value, they are input to the input stream in the order they arrived at the SDP server.
The figure below shows an example of when the time set in records in a tuple is after the current reference time. In this example, sec is specified for the unit of time and 2 is specified for the length of time to be adjusted.

Figure 10-28 Example of when the time set in the records in a tuple is after (subsequent to) the current reference time

[Figure]
In this example, the reference time is 09:00:01 and the range of times to be adjusted is 09:00:01-08:59:59. When a new tuple with 09:00:02:056 set as the time in the records is sent from the input adaptor, the reference time changes to 09:00:02 because this tuple's time is subsequent to the existing reference time. As a result, the range of times to be adjusted changes to 09:00:02-09:00:00.
This new tuple is held by the timestamp adjustment function with a timestamp of 09:00:02.
The tuple with the timestamp 08:59:59 is input to the input stream because it is not within the new time adjustment range.
Time set in records in the tuple is within the range of times to be adjusted
If the time set in records in the tuple sent from the input adaptor is within the range of times to be adjusted, the tuple is held by the timestamp adjustment function.
The figure below shows an example of when the time set in records in a tuple is within the range of times to be adjusted. In this example, sec is specified for the unit of time and 2 is specified for the length of time to be adjusted.

Figure 10-29 Example of when the time set in records in a tuple is within the range of times to be adjusted

[Figure]
In this example, the reference time is 09:00:01 and the range of times to be adjusted is 09:00:01-08:59:59. When a new tuple with 09:00:01:010 set as the time in the records is sent from the input adaptor, it is held by the timestamp adjustment function with a timestamp of 09:00:01 because the time set in its records is within the range of times to be adjusted. Similarly, if a tuple with 08:59:59.800 set as the time in its records is sent from the input adaptor, it will be held by the timestamp adjustment function with a timestamp of 08:59:59.
Time set in records in the tuple is earlier than the range of times to be adjusted
If the time set in records in the tuple sent from the input adaptor is before the range of times to be adjusted, the timestamp adjustment function discards the tuple and outputs a log to that effect to the tuple log.
The figure below shows an example of when the time set in records in a tuple is earlier than the range of times to be adjusted. In this example, sec is specified for the unit of time and 2 is specified for the length of time to be adjusted.

Figure 10-30 Example of when the time set in records in a tuple is earlier than the range of times to be adjusted

[Figure]
In this example, the reference time is 09:00:01 and the range of times to be adjusted is 09:00:01-08:59:59. When a new tuple with 08:59:58:010 set as the time in its records is sent from the input adaptor, that tuple is discarded because the time set in its records is earlier than the range of times to be adjusted. A log to that effect is then sent to the tuple log.

(2) Order in which tuples are input to the input stream

Tuples whose time information has been adjusted by the timestamp adjustment function are input to the input stream in ascending order of the timestamps set by the timestamp adjustment function. In the case of multiple tuples with the same timestamp value, they are input to the input stream in the order they arrived at the SDP server.

If tuples have different units of time and ranges to be adjusted by the timestamp adjustment function, the order in which they are input to the input stream depends on several factors.

This subsection presents examples for different combinations of the unit of time and the range of times to be adjusted in order to discuss the timestamp set in tuples by the timestamp adjustment function and the order in which tuples would be input to the input stream.

The examples presented here assume that tuples A through E shown in the table below are sent from the input adaptor:

TupleOrder sent from input adaptorTime set in records in the tuple
A12009/03/01 12:15:22:345678901​
B22009/03/01 12:15:22:123456789​
C32009/03/01 12:15:23:123456789​
D42009/03/01 12:15:22:890123456​
E52009/03/01 12:15:24:123456789​
When sec is specified as the unit of time and 1 is specified for the range of times to be adjusted:
The table below shows the timestamps set in these tuples by the timestamp adjustment function and the order in which the tuples are input to the input stream when sec is specified as the unit of time and 1 is specified for the range of times to be adjusted.
Note that when sec is specified as the unit of time, the timestamp is expressed in whole seconds and any fractional part of a second is discarded.
TupleInput orderTimestamp set by timestamp adjustment function
A12009/03/01 12:15:22:000000000​
B22009/03/01 12:15:22:000000000​
C42009/03/01 12:15:23:000000000​
D32009/03/01 12:15:22:000000000​
E52009/03/01 12:15:24:000000000​
In this example, all tuples are input to the input stream because they all fall within the time adjustment range.
When msec is specified as the unit of time and 999 is specified for the range of times to be adjusted:
The table below shows the timestamps set in these tuples by the timestamp adjustment function and the order in which the tuples are input to the input stream when msec is specified as the unit of time and 999 is specified for the range of times to be adjusted.
Note that when msec is specified as the unit of time, the timestamp is expressed in whole milliseconds and any fractional part of a millisecond is discarded.
TupleInput orderTimestamp set by timestamp adjustment function
A22009/03/01 12:15:22:345000000​
B12009/03/01 12:15:22:123000000​
C42009/03/01 12:15:23:123000000​
D32009/03/01 12:15:22:890000000​
E52009/03/01 12:15:24:123000000​
In this example, all tuples are input to the input stream because they are all within the time adjustment range.
When usec is specified as the unit of time and 999 is specified for the range of times to be adjusted:
The table below shows the timestamps set in these tuples by the timestamp adjustment function and the order in which the tuples are input to the input stream when usec is specified as the unit of time and 999 is specified for the range of times to be adjusted.
Note that when usec is specified as the unit of time, the timestamp is expressed in whole microseconds and any fractional part of a microsecond is discarded.
TupleInput orderTimestamp set by timestamp adjustment function
A12009/03/01 12:15:22:345678000​
BDiscardedNone set
C22009/03/01 12:15:23:123456000​
DDiscardedNone set
E32009/03/01 12:15:24:123456000​
In this example, once tuple A's timestamp becomes the reference time, tuple B is discarded because its time is earlier than this reference time and is outside the range of times to be adjusted. Similarly, tuple D is discarded because its time is earlier than that of tuple C and is also outside the range of times to be adjusted.
When sec is specified as the unit of time and 0 is specified for the range of times to be adjusted:
The table below shows the timestamps set in these tuples by the timestamp adjustment function and the order in which the tuples are input to the input stream when sec is specified as the unit of time and 0 is specified for the range of times to be adjusted.
Note that when sec is specified as the unit of time, the timestamp is expressed in whole seconds and any fractional part of a second is discarded.
TupleInput orderTimestamp set by timestamp adjustment function
A12009/03/01 12:15:22:000000000​
B22009/03/01 12:15:22:000000000​
C32009/03/01 12:15:22:000000000​
DDiscardedNone set
E42009/03/01 12:15:23:000000000​
In this example, only the reference time is within the time adjustment range. When tuple C is sent, its timestamp becomes the reference time and tuple D is discarded because its time is earlier than the reference time.