All Products
Search
Document Center

Realtime Compute for Apache Flink:LAST_VALUE

Last Updated:Mar 26, 2026

LAST_VALUE returns the last non-null value in a data stream within an OVER window. Use it to track the most recent valid value for each partition as new records arrive.

Limits

Supported only in Realtime Compute for Apache Flink that uses Ververica Runtime (VVR) 3.0.0 or later.

Syntax

T LAST_VALUE(T value)
T LAST_VALUE(T value, BIGINT order)

Input parameters

ParameterData typeDescription
valueAny data typeThe value to evaluate. Null values are skipped.
orderBIGINTA ranking key that determines which record is considered last. The non-null record with the largest order value is returned.
Important

All input parameters must be of the same data type.

Return value

Returns the same data type as value.

Usage notes

Using the order parameter

When you provide an order value, LAST_VALUE selects the non-null record with the largest order value instead of relying on processing order.

Example

Test data (table T1)

a (BIGINT)b (INT)c (VARCHAR)
11Hello
22Hello
33Hello
44Hello
55Hello
66Hello
77NULL
87Hello World
98Hello World
1020Hello World

Test statement

SELECT c, LAST_VALUE(b)
OVER (PARTITION BY c ORDER BY PROCTIME() RANGE UNBOUNDED PRECEDING) AS var1
FROM T1;

Result

c (VARCHAR)var1 (INT)
Hello1
Hello2
Hello3
Hello4
Hello5
Hello6
NULL7
Hello World7
Hello World8
Hello World20

The NULL row in c returns var1 = 7 because that partition contains only one row (b = 7). For the Hello World partition, each row reflects the last non-null b value up to and including that row (7, then 8, then 20), because the window frame is RANGE UNBOUNDED PRECEDING.