This topic describes how to use the LAST_VALUE function. This function returns the last non-null record of a data stream.

Notice This topic applies only to Ververica Platform (VVP) 2.4.0, Ververica Runtime (VVR) 3.0.0, and later.

Syntax

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

Input parameters

Parameter Data type Description
value Any data type A data stream.
order BIGINT The non-null record that has the largest order value is considered the last non-null record.
Notice All input parameters must be of the same data type.

Example

  • Test data
    Table 1. T1
    a(BIGINT) b(INT) c(VARCHAR)
    1 1 Hello
    2 2 Hello
    3 3 Hello
    4 4 Hello
    5 5 Hello
    6 6 Hello
    7 7 NULL
    8 7 Hello World
    9 8 Hello World
    10 20 Hello World
  • Test statement
    SELECT c,LAST_VALUE(b) 
    OVER (PARTITION BY c ORDER BY PROCTIME() RANGE UNBOUNDED PRECEDING) AS var1
    FROM T1;
  • Test results
    c(VARCHAR) var1(INT)
    Hello 1
    Hello 2
    Hello 3
    Hello 4
    Hello 5
    Hello 6
    NULL 7
    Hello World 7
    Hello World 8
    Hello World 20