MAX

Returns the maximum value of a group of values from a windowed query. A windowed query
is defined in terms of time or rows.
For information about window queries, see Windowed Queries.

When you use MAX, be aware of the following:

If you don't use the OVER clause, MAX is calculated as an aggregate function. In this case,
the aggregate query must contain a GROUP BY clause on a monotonic expression based on ROWTIME that
groups the stream into finite rows. Otherwise,
the group is the infinite stream, and the query will never complete and no rows will
be emitted. For more information, see Aggregate Functions.

Syntax

Tumbling Windowed Query

Sliding Windowed Query

MAX(number-expression) OVER window-specification

Parameters

number-expression

Specifies the value expressions evaluated for each row in the aggregation.

OVER window-specification

Divides records in a stream partitioned by the time range interval or the number of
rows.
A window specification defines how records in the stream are partitioned by the time
range interval or the number of rows.

GROUP BY monotonic-expression | time-based-expression

Groups records based on the value of the grouping expression returning a single summary
row for each group of rows that has identical values in all columns.

Examples

Example Dataset

The examples following are based on the sample stock dataset that is part of Getting Started in the
Amazon Kinesis Analytics Developer Guide. To run each example, you need an Amazon Kinesis Analytics application that has the
sample stock ticker input stream.
To learn how to create an Analytics application and configure the sample stock ticker
input stream,
see Getting Started in the Amazon Kinesis Analytics Developer Guide.

Results

The preceding examples output a stream similar to the following.

Example 2: Return the Maximum Value Using the OVER Clause

In this example, the OVER clause divides records in a stream partitioned by the time range interval of '1'
hour preceding.
The MAX function is then calculated from the rows returned by the OVER clause.