ROWTIME - Amazon Kinesis Data Analytics SQL Reference

ROWTIME

ROWTIME is an operator and system column that returns the time at which a particular row of a stream was created.

It is used in four distinct ways:

  • As an operator

  • As a system column of a stream

  • As a column alias, to override the timestamp on the current row

  • As an ordinary column in a table

For more details, see the topics Timestamp, ROWTIME, and CURRENT_ROW_TIMESTAMP in this guide.

ROWTIME operator

When used in the SELECT clause of a streaming query, without being qualified by a preceding 'alias.' , ROWTIME is an operator that evaluates to the timestamp of the row that is just about to be generated.

Its type is always TIMESTAMP NOT NULL.

ROWTIME system column

Every stream has a ROWTIME column. To reference this column from within a query, qualify it with the stream name (or alias). For example, the following join query returns three timestamp columns: the system columns of its input streams, and the timestamp of the generated row.

SELECT STREAM  o.ROWTIME AS leftRowtime,  s.ROWTIME AS rightRowtime,  ROWTIME AS joinRowtime FROM Orders AS o  JOIN Shipments OVER (RANGE INTERVAL '1' HOUR FOLLOWING) AS s  ON o.orderId = s.orderId leftRowtime         rightRowtime        joinRowtime =================== =================== =================== 2008-02-20 10:15:00 2008-02-20 10:30:00 2008-02-20 10:15:00 2008-02-20 10:25:00 2008-02-20 11:15:00 2008-02-20 10:25:00 2008-02-20 10:25:30 2008-02-20 11:05:00 2008-02-20 10:25:30

As it happens, leftRowtime is always equal to joinRowtime, because the join is specified such that the output row timestamp is always equal to the ROWTIME column from the Orders stream.

It follows that every streaming query has a ROWTIME column. However, the ROWTIME column is not returned from a top-level JDBC query unless you explicitly include it in the SELECT clause. For example:

CREATE STREAM Orders(  "orderId" INTEGER NOT NULL,  "custId" INTEGER NOT NULL); SELECT columnName FROM ALL_STREAMS; columnName ========== orderId custId SELECT STREAM * FROM Orders; orderId custId ======= ======    100    501    101     22    102    699 SELECT STREAM ROWTIME, * FROM Orders; ROWTIME             orderId custId =================== ======= ====== 2008-02-20 10:15:00     100    501 2008-02-20 10:25:00     101     22 2008-02-20 10:25:30     102    699

This is mainly to ensure compatibility with JDBC: the stream Orders declares two columns, so it makes sense that "SELECT STREAM *" should return two columns.