This topic describes how to use the FIRST_VALUE function. This function returns the first 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

FIRST_VALUE( T value )
FIRST_VALUE( T value, BIGINT order )

Input parameters

Parameter Data type Description
value Any data type A data stream.
Note If all input data is NULL, NULL is returned.
order BIGINT The non-null record that has the smallest order value is considered the first 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,FIRST_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 1
    Hello 1
    Hello 1
    Hello 1
    Hello 1
    NULL 7
    Hello World 7
    Hello World 7
    Hello World 7