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

Limits

This function is 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 type A data stream.
orderBIGINTThe non-null record that has the largest order value is considered the last non-null record.
Important All input parameters must be of the same data type.

Example

  • Test data
    Table 1. 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;
  • Test result
    c(VARCHAR)var1(INT)
    Hello1
    Hello2
    Hello3
    Hello4
    Hello5
    Hello6
    NULL7
    Hello World7
    Hello World8
    Hello World20